【发布时间】:2013-06-25 19:04:23
【问题描述】:
我在三台不同的计算机上安装了三台网络服务器。我正在尝试安装一个 php 应用程序,它将所有 url 请求重写为 index.php(前端控制器模式)。以下 .htaccess 适用于三台 Web 服务器中的两台:
RewriteEngine On
# Redirect everything to the Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^(css|images|files)/ index.php [NC,L]
所以,当我访问 http://example.com/hithere 时,会调用 index.php,然后我可以解析最初请求的 url (hithere) 以确定将其发送到哪个控制器。
但是,由于某些未知原因,上述 .htaccess 文件在第三个网络服务器上不起作用。相反,当我访问 http://example.com/hithere 时,我的浏览器中出现 404 not found 错误,提示如下:
The requested URL /full/path/to/application/index.php was not found on this server.
因此,基于上述错误,我可以看出它实际上是在尝试重定向到 index.php。但是浏览器在下面/full/path/... 中列出的文件实际上在我的网络服务器上——所以我不知道为什么它找不到它。有人可以帮助我并告诉我我做错了什么吗?
编辑:我不知道 httpd.conf 中是否有冲突,但这里是我在 httpd.conf 中针对此应用程序所在目录的设置
Alias /myapp /full/path/to/my/app
<Directory /full/path/to/my/app>
Order allow,deny
AllowOverride All
Allow from all
</Directory>
编辑 2: 我注意到 Apache 日志中有一些特殊之处。看起来 Apache 正在将我试图将流量重定向到的 index.php 附加到 DocumentRoot:
File does not exist: /document/root/full/path/to/my/app/index.php
什么时候应该去:
/full/path/to/my/app/index.php
所以我基本上需要告诉 htaccess 忽略文档根目录。我通过在我的 .htaccess 文件中指定这个来尝试这个:
RewriteBase /full/path/to/my/app/
但它仍在为 index.php 搜索文档根目录:/ 有没有办法重置 DocumentRoot 或告诉 htaccess 在重写 index.php 时忽略它?即使我在 RewriteRule 中使用绝对路径,它仍然会将其附加到文档根目录。
RewriteEngine On
# Redirect everything to the Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^(css|images|files)/ /full/path/to/my/app/index.php [NC,L]
这对我来说没有意义...有人可以帮忙吗?
谢谢
【问题讨论】:
-
第三个 Web 服务器是否启用了 mod_rewrite?
-
第三个 Web 服务器是否将 AllowOverride 设置为您的 .htaccess 所在目录的足够高的级别?
-
@faffaffaff 是的,httpd.conf 文件包含 AllowOverride All。我已经使用此应用程序的相关 httpd.conf 设置编辑了问题,也许它在那里?感谢您的帮助
-
检查您的 apache 日志。
-
你能显示
ls -lZ /full/path/to/application/的输出吗?
标签: php apache .htaccess mod-rewrite