开发者

htaccess / mod_rewrite problems with possible subdirectories

开发者 https://www.devze.com 2023-01-11 15:53 出处:网络
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.

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.

When it is pointed to /somepath there are no problems, but when its not it seems like when i req开发者_运维问答uest /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.

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?

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!


I don't think this is possible. But this sounds like a construction error either way. It would be much better to incorporate the two .htaccess files into one. (Or is the second one in /somepath even necessary? Why?)

Under which circumstances does the request's domain point to /somepath? Is it a different domain you could use in a RewriteCond of its own?


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 /.

Assuming we're all on the same page about the document root, we can accomplish this by modifying /somepath/.htaccess:

Edit: 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号