Reputation: 11635
How can I redirect all images that look like this:
http://site.com/subdir/a/b/c/image.jpg
to something like this:
http://site.com/a/b/c/image.jpg
using htaccess rewrite rules. Only http://site.com/subdir/
is fixed, the rest of the paths are variable (can change).
Basically I want to take out "subdir/" from the path...
Upvotes: 1
Views: 1225
Reputation: 12727
Put this : in your .htaccess
in your DocumentRoot
.
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBasae /
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteRule ^subdir/(\w+)/(\w+)/(\w+)/([\w\d-]+\.[\w]+)/?$ /$1/$2/$3/$4 [NC,R=301,L]
RewriteRule ^(\w+)/(\w+)/(\w+)/([\w\d-.]+\.[\w]+)/?$ subdir/$1/$2/$3/$4 [L]
Upvotes: 2
Reputation: 1029
Try this.
http://php.net/manual/en/function.basename.php
use base name instead of the path..
Upvotes: 2