【发布时间】:2014-12-21 21:03:21
【问题描述】:
我的 .htaccess 遇到了一个非常奇怪的行为。每当我尝试访问由 mod_rewrite 重写的链接时,我的 .htaccess 引用的是根目录,而不是我正在使用的子目录。我的文件夹结构如下所示:htdocs/
blog6/
.htaccess
我的 .htaccess 看起来像这样:
Options +FollowSymLinks -MultiViews
ErrorDocument 401 /core/error/401.php
ErrorDocument 403 /core/error/403.php
ErrorDocument 404 /core/error/404.php
ErrorDocument 500 /core/error/500.html
RewriteEngine on
RewriteBase /blog6/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /index.php?page=$1 [L]
但是每当我尝试通过重写的 url 访问文件时,我都会收到 404 错误,并且日志显示:
C:/xampp/htdocs/index.php' not found or unable to stat
所以看起来我的 .htaccess 想要访问 htdocs 中的文件而不是使用子目录。当我在我的 rewriteRule 中写 /blog6 时,一切正常,但为什么 RewriteBase 不能正常工作?如果它很重要,我在我的 html 中使用 <base>
【问题讨论】:
-
您在浏览器中打开的哪个 URL 会导致此 404?我相信这个 .htaccess 在
/blog6/目录中? -
@anubhava 是的,.htaccess 在
/blog6/中。我打开http://localhost/blog6/login,它应该是http://localhost/blog6/index.php?page=login的重写形式。如果我在 rewriteRule 前面放一个blog6/,它看起来像这样:RewriteRule ^([^/]*)$ /blog6/index.php?page=$1 [L]并且可以工作。这就是让我感到困惑的地方,因为 rewriteBase 没有影响......
标签: apache .htaccess mod-rewrite redirect rewrite