htaccess的/ mod_rewrite的问题可能出现的子目录 [英] htaccess / mod_rewrite problems with possible subdirectories
问题描述
我的工作一个非常动态的系统,我在/和/ somepath两个相同htaccess的文件上。这样做的原因,该域名可以指出成/ somepath,但我从来不知道这是否是。
I am working on a very dynamic system where i have two identical htaccess files in / and in /somepath. The reason for this that the domain could be pointed into /somepath, but i never know if it is.
当它指向/ somepath不存在任何问题,但它不是好像当我请求/ somepath /页/富如/酒吧,位于/ somepath覆盖一个在/ htaccess的文件。在后一种情况下,我不希望/somepath/.htaccess运行在所有的,或至少漠视mod_rewrite的在里面。
When it is pointed to /somepath there are no problems, but when its not it seems like when i request /somepath/page/foo/bar the htaccess file in /somepath overrides the one in /. In the latter case i dont want the /somepath/.htaccess to run at all, or at least disregard the mod_rewrite in it.
一个解决办法是,如果我可以检查,如果后者htaccess并不位于文档根目录。这可能吗?如何才能从htacces内htaccess的路径文档根我比较文件?
One solution would be if i could check if the latter htaccess is not located in the document root. Is this possible? How can i compare the htaccess path to document root from within the htacces file?
这两个htaccess的文件是这样的:
Both htaccess files look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule .* uri_handler.php [L]
</IfModule>
有谁知道什么是怎么回事? 谢谢!
Does anyone know whats going on here? Thanks!
推荐答案
除非任何企图简化你的设置,我觉得这里最简单的方法是只确保了的.htaccess
文件 / somepath
不处理请求 / somepath
当文档根目录为 /
。
Barring any attempts at simplifying your setup, I think that the easiest approach here is to just make sure that the .htaccess
file in /somepath
doesn't handle requests to /somepath
when the document root is /
.
假设我们所有关于文档根在同一页上,我们可以通过修改 /somepath/.htaccess
做到这一点:
Assuming we're all on the same page about the document root, we can accomplish this by modifying /somepath/.htaccess
:
编辑:的更简单的方法是只拥有它总是要求 uri_handler.php
,生活在根:
The easier way is to just have it always request the uri_handler.php
that lives at the root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule .* /uri_handler.php [L]
</IfModule>
这篇关于htaccess的/ mod_rewrite的问题可能出现的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!