patrico
patrico

Reputation: 5

Redirect from subfolder and folder to main folder with htaccss

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

Answers (2)

Amit Verma
Amit Verma

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

anubhava
anubhava

Reputation: 785156

You just need one single rule in your root .htaccess for all these redirects:

RedirectMatch 301 /[^/]+/([^/]+)/?$ /$1

Upvotes: 0

Related Questions