Revo Burisan Revo Burisan - 5 months ago 48
Apache Configuration Question

Using variable in mod_rewrite on redirect

I have following code, that works perfectly but my problem is I dont want to birds hard coded in RewriteRule.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /birds/$1 [L,R=301]

I dont want to add it manually because there are many folders like "birds"




but in my case it returns to


You can capture full URI path from RewriteCond %{REQUEST_URI} instead of RewriteRule which is relative to current directory:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(/.*)/$
RewriteRule /$ %1 [L,R=301,NE]