How make rewrite rules relative to .htaccess file.
Posted
by Kendall Hopkins
on Server Fault
See other posts from Server Fault
or by Kendall Hopkins
Published on 2010-06-02T21:48:18Z
Indexed on
2010/06/02
21:56 UTC
Read the original article
Hit count: 321
apache
|mod-rewrite
Current I have an .htaccess file like this.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} ^/(always|rewrite|these|dirs)/ [NC]
RewriteRule ^(.*)$ router.php [L,QSA]
It works create when the site files are in the document_root of the webserver (ie. domain.com/abc.php -> /abc.php). But in our current setup (which isn't changeable), this isn't ensured. We can sometimes have arbitrary folder in between the document root and folder of the .htaccess file (ie. domain.com/something/abc.php -> /something/abc.php). The only problem with is that is the second RewriteCond
no longer works. Is there anyway to dynamically check if the accessed path by a path relative to .htaccess file.
For Example:
If I have a site where domain.com/rewrite/ is the directory of the .htaccess file.
NOT FORCED TO REWRITE -> domain.com/rewrite/index.php
FORCED TO REWRITE -> domain.com/rewrite/rewrite/index.php
If I have a site where domain.com/ is the directory of the .htaccess file.
NOT FORCED TO REWRITE -> domain.com/index.php
FORCED TO REWRITE -> domain.com/rewrite/index.php
© Server Fault or respective owner