mod_rewrite 与 Alias 指令冲突
我的主要网站使用 PHP/Zend Framework,.htaccess 是常见的:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
现在我需要将一个论坛(在另一个目录中)带到主站点。我在 VirtualHost 中添加了 Alias 指令
Alias /forums "h:/projects/forums"
论坛软件使用自己的 .htaccess。主要 URL /forums 可以访问,但其他 URL 不能访问。其他URL(没有相应文件的URL)将转发到主站点。换句话说,会选取主站点 (/) 的 .htaccess 文件,而不是 /forums 目录下的 .htaccess 文件。
My primary web site uses PHP/Zend Framework, and the .htaccess is the common one:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Now I need to bring a forum (in another directory) to the main site. I added an Alias directive inside VirtualHost
Alias /forums "h:/projects/forums"
The forum software uses its own .htaccess. The main URL /forums is accessible but not others. Other URLs (those who do not have corresponding files) are forwarded to the main site. In other words, the .htaccess file of the main site (/) is picked up, not the one under /forums directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加新的
RewriteCond
来告诉您的主.htaccess
文件忽略/forums
下的请求。请求通过该文件后,它应该被/forums/.htaccess
文件接收,尽管我承认我不太确定Alias
影响这个。条件如下所示:
这表示“如果请求不是以
/forums
开头,则仅执行下一个RewriteRule
”。最后的[NC]
表示忽略/forums
上的大小写,因此请求是否实际上是针对/Forums
并不重要或/FORUMS
。Try adding a new
RewriteCond
to tell your main.htaccess
file to ignore requests under/forums
. After the request passes through that file, it should get picked up by the/forums/.htaccess
file, though I'll admit that I'm not really sure ifAlias
affects this.The condition would look like this:
This says "only perform the next
RewriteRule
if the request doesn't begin with/forums
". The[NC]
at the end says to ignore the casing on/forums
so it won't matter if the request is actually for/Forums
or/FORUMS
.