首页 > 解决方案 > 我应该如何成功重写 url 以在远程服务器上使用?

问题描述

我的网站在本地主机上正常工作,但在上传到远程服务器时,只有 index.php 页面在工作。其他 URL,如登录(见下文)不起作用并返回 404 Not Found 错误。

模型-视图-控制器设计模式已经实现,因此站点上的所有页面都使用适当的视图文件通过 index.php 呈现。

简单地说,该网站的设计工作如下:

下面是我的 .htaccess 文件 - 也存储在上面的 /public 文件夹中。上传到远程服务器后,我对该文件所做的唯一更改是在 RewriteBase 行上。

    Options -MultiViews
    RewriteEngine On

    ######################
    # Localhost version of the RewriteBase statement:
    # RewriteBase /subdom/public
    ######################

    # Remote server version of the RewriteBase statement (as displayed in host's cPanel):
    RewriteBase /home2/user/subdom.mysite.com/public

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)$ index.php?atid=$1 [QSA,L]

在过去的几天里,我一直在为这个问题而烦恼。我不知道我遗漏了什么或需要进行哪些修改,因此非常感谢您的帮助以使其正常工作。

标签: apache.htaccessmodel-view-controllerurl-rewritingurl-routing

解决方案


推荐阅读