BerrKamal
BerrKamal

Reputation: 89

Redirect duplicate urls in htaccess

I have a big list of duplicate urls and i need to do some redirect

Example

www.mysite.com/mypage/name2_68.html   
www.mysite.com/jjj/name2_68.html   
www.mysite.com/aa/name2_68.html   
www.mysite.com/5654/name2_68.html   

www.mysite.com/mypage/myname87.html   
www.mysite.com/6584/myname87.html   
www.mysite.com/any-number/myname87.html   
www.mysite.com/any_word/myname87.html   

All i need to do is to redirect them to

www.mysite.com/mypage/myname87.html   
www.mysite.com/mypage/name2_68.html   

So all url with

www.mysite.com/anycharactere/example1.html    

Will be redirect to

www.mysite.com/mypage/example1.html

Upvotes: 1

Views: 141

Answers (2)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

This should work.

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/mypage/?
RewriteRule ^[^/]+/(.*\.html?)$ /mypage/$1 [R=301,L]

Upvotes: 1

wachme
wachme

Reputation: 2337

Put it in your .htaccess

RewriteEngine On
RewriteRule .*/([^/]+.html)$ /mypage/$1

Upvotes: 0

Related Questions