Reputation: 5186
I want to append the request to a script.
example.com -> example.com/d.php
example.com/css/style.css -> example.com/d.php/css/style.css
example.com/api/ShowPdf?bar=Foo -> example.com/d.php/api/ShowPdf?bar=Foo
and so on.
I tried
RewriteEngine On
RewriteRule /(.+) d.php/$1
This works only for example.com
. All other requests result in "Maximum number of redirect reached
" and the server returns error 500.
What am I doing wrong? How can I achieve this simple redirect which should be valid for every request?
Upvotes: 0
Views: 22
Reputation: 42875
The rewriting engine works in loops. After one run is done the engine starts over again, if the request has actually been rewritten. You pattern matches any requests, regardless how often it already has been rewritten. So the rule gets applied again and again. You need some way to break that cycle:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/d.php
RewriteRule ^/(.+) /d.php/$1
Alternatively you don't even have to capture the actual request path:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/d.php
RewriteRule ^ /d.php%{REQUEST_URI}
That form works in the central configuration (as you currently do and which should be preferred in most cases), but also in a distributed configuration file (usually named ".htaccess"), if that is requried:
Upvotes: 0