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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.