Shina
Shina

Reputation: 2066

htaccess - Redirecting duplicate urls to one page without having to do multiple times

I have a duplicate urs like www.domain.com/en/article and www.domain.com/article ... they are both going to same page.

Now we are re-building the site and we would like to redirect duplicate urls like the above to one page without having to do it multiple times, like is there a regex or something of such.

This is the standard one I know: #Redirect 301 /login http://www.domain.com/index.php?option=login

Any suggestion?

Thanks in advance

Upvotes: 1

Views: 203

Answers (3)

eintro-pl
eintro-pl

Reputation: 1

How to correctly implement -problem duplicate pages .htaccess

RewriteCond %{HTTP_HOST} ^eintro.pl(.*) [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.eintro.pl/$1 [R,L]
RewriteRule ^index.html$ http://%{HTTP_HOST}/$1 [L,R=301]

Upvotes: 0

Ravi Dhoriya ツ
Ravi Dhoriya ツ

Reputation: 4414

Try this

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/new_(.*)$
RewriteRule ^(en)?/?(.*)$ /new_$2 [R=301,QSA,L]

It will redirect:

  1. www.domain.com/en/article or www.domain.com/article to www.domain.com/new_article

  2. www.domain.com/en/another_article or www.domain.com/another_article to www.domain.com/new_another_article

  3. www.domain.com/en/another_article2 or www.domain.com/another_article2 to www.domain.com/new_another_article2

and so on..

Upvotes: 0

anubhava
anubhava

Reputation: 785286

You can use this rule:

RewriteEngine On
RewriteRule (^|/)article/?$ /new_article [R=301,NC,L]

Upvotes: 2

Related Questions