views:

29

answers:

1

I have a server where I can only configure httpd using .htaccess, a cannot access global configuration. I want to rewrite almost every non-existing path to index.php, so I did something like:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [L,QSA]

And that is ok. But another thing I want to do is to prevent access to path where I keep PHP files (I cannot store them somewhere else) which is for example /php. I would like that anything starting with /php rewrites to index.php?path=php... so I did something like:

RewriteCond %{REQUEST_URI} ^/php.*
RewriteRule ^(.*)$ /index.php?path=$1 [L,QSA]

And that also would work ok if I had access to global configuration. In case of per-directory configuration, when I access /php it rewrites it to index.php?path=php and than puts directory name before that: /php/index.php?path=php. I read documentation and I realize that it uses internal redirects when per-directory confoguration is used. How can I avoid this behavior?

A: 

You can use Deny from all instead of mod_rewrite, but if you really want it, you can force external redirects as noteed in the mod_rewrite docs:

If a substitution string starts with http://, then the directory prefix will not be added

wRAR
Result is OK but I would like to avoid external redirects. Also, I will rather use deny from all option, but I wanted to hide it from outside world, not just forbid it. Thnx
justnoone
You can try `RewriteBase`, though I still don't know what can it be used for.
wRAR
I tried that too, but it seems that it uses that before rewrite, when testing URL and it adds prefix after...
justnoone