I’m trying to create a RewriteRule as follows;
RewriteCond %{HTTP_HOST} ^dev$ [NC]
RewriteRule ^(.*)$ test/$1 [L]
When someone enters in http://dev/index.php that actually the file that will be retrieved is http://dev/test/index.php.
However this seems to cause a load of internal redirects.
Any anyone help?
Add
…before the first
RewriteCond.The
[L]flag on a rewrite rule (slightly counter-intuitively) causes the rewriting process to begin again again from the top. Your current rules will match on every iteration, and mod_rewrite will get into an infinite loop. Adding the aboveRewriteCondmeans that it will only match on the first iteration.If you are running on Apache 2.3.9 or later, you could use the
[END]flag on the rewrite rule instead of[L]– this will cause mod_rewrite to exit immediately and avoid the problem. This would actually be a better solution if it is available, as the aboveRewriteCondwould prevent your rule from working for a page that legitimately begins withtest.