Reputation: 5
I want a redirect for links :
http://www.domain.com/folder/file.php **to* http://www.domain.com/file.php
http://www.domain.com/folder/folder/file.php **to* http://www.domain.com/file.php
So far I have tried this
Redirect 301 /folder/file.php http://www.domain.com/file.php
Redirect 301 /folder/folder/file.php http://www.domain.com/file.php
This is working .I have 100more files like this to redirect , is there an easy way to reduce my code so that I can have less code to redirect more. thanks for your help!
Upvotes: 0
Views: 47
Reputation: 41219
You can use RedirectMatch directive :
Put the following Redirects above other rules in your root/.htaccess file :
RedirectMatch 301 ^/folder/folder/([^/]+)/?$ /$1
RedirectMatch 301 ^/folder/([^/]+)/?$ /$1
Upvotes: 1
Reputation: 785156
You just need one single rule in your root .htaccess for all these redirects:
RedirectMatch 301 /[^/]+/([^/]+)/?$ /$1
Upvotes: 0