【问题标题】:mod_rewrite not working for a specific directorymod_rewrite 不适用于特定目录
【发布时间】:2009-10-05 21:16:30
【问题描述】:

这已经让我彻底迷惑了几天,我相信一旦解决它我会看起来很愚蠢,但如果我现在不寻求帮助会更愚蠢。

我有 mod_rewrite 在我的 localhost 上成功运行(不涉及虚拟主机;这是我的笔记本电脑,我的开发机器),我在各种目录中使用 .htaccess 来帮助将粗糙的 URL 重写为清理 URL。除了...它在一个目录中不起作用。由于无法在此问题中重现我的整个笔记本电脑,因此我提供以下详细信息。

在我的 httpd.conf 中,我加载了 mod_rewrite.so。

LoadModule rewrite_module modules/mod_rewrite.so

在我的 httpd.conf 中,我包含了另一个类似这样的 conf 文件

Include /usr/local/apache2/conf/other/punkish.conf

在我的 punkish.conf 中,我有这样定义的目录

DocumentRoot "/Users/punkish/Sites"
<Directory "/Users/punkish/Sites">
  Options ExecCGI
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

<Directory "/Users/punkish/Sites/one">
  Options FollowSymLinks
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

<Directory "/Users/punkish/Sites/two">
  Options FollowSymLinks
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

在 ~/Sites/one 我有以下 .htaccess 文件

RewriteEngine On
RewriteBase /one/

# If an actual file or directory is requested, serve directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise, pass everything through to the dispatcher
RewriteRule ^(.*)$ index.cgi/$1 [L,QSA]

而且,一切正常。但是,在我的目录中 ~/Sites/two 我有以下 .htaccess 文件

RewriteEngine On
RewriteBase /two/

# If an actual file or directory is requested, serve directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise, pass everything through to the dispatcher
RewriteRule ^(.*)$ index.cgi/$1 [L,QSA]

而且,没有任何效果。纳达。压缩。齐尔奇。我只是得到一个 404。我已经确定 mod_rewrite 甚至没有通过在其中放入虚假命令来查看我的 ~/Sites/two/.htaccess 并且除了 404 之外没有收到任何错误。

另一个令人困惑的问题——我在 httpd.conf 中使用 RewriteLogLevel 3 打开了 RewriteLog,但我的 rewrite_log 完全为空。我知道这很难解决,除非亲自坐在有问题的计算机前,但我希望有人能告诉我发生了什么。

**更新:** 没有任何地方涉及别名。这是我的笔记本电脑,一切都在上述文档根目录下,所以我只需以http://localhost/ 访问每个目录。是的,拼写错误的可能性很大(我确实说过一旦解决它我会看起来很愚蠢,但是,目前我还没有在任何地方发现一个拼写错误,是的,我现在已经重新启动了 Apache 大约十几次。我什至以为我可能有两个不同的 Apache 正在运行,但不,我只有一个,在 /usr/local/apache2 下的一个,我前一段时间自己安装了它。

【问题讨论】:

  • 仔细检查verrrry是否有错别字——尤其是在目录名称中。另外,重新启动 apache :)

标签: .htaccess mod-rewrite


【解决方案1】:

您在此处所代表的所有内容都有一个外部因素使情况变得混乱;具体来说,像Alias 之类的东西会导致对/two 的请求转到~punkish/Sites/two 以外的其他地方。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 2013-11-20
    • 1970-01-01
    相关资源
    最近更新 更多