Reputation: 23
I need to redirect all php files from end of urls to a specif dir like:
http://example.com/dir/file.php
http://example.com/dir/folder/file.php
http://example.com/dir/folder/folder2/file.php
to
http://example.com/dir2/file.php
my code is
RewriteRule ^(.*).php$ http://example.com/dir2/$1.php [R=301,L]
but I'm getting
http://example.com/dir2//dir/file.php
Upvotes: 2
Views: 47
Reputation: 41219
You can use the following :
RewriteRule ^.*/?([^/.]+).php$ http://example.com/dir2/$1.php [R=301,L]
This will just capture /file.php
in the regex and not the directory.
Upvotes: 1