Revo Burisan Revo Burisan - 2 years ago 226
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

Answer Source

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]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download