Y
Y
Yuriy2020-06-10 10:30:37
htaccess
Yuriy, 2020-06-10 10:30:37

How to remove duplicate words in URL using .htaccess?

Duplicate pages came out, tell me the regular expression for duplicate words in the URL,

links like
https://site.ru/shop/shop/
https://site/shop/shop/catalog/
https://site/shop/shop/catalog/ element/

should be redirected to

https://site.ru/shop/
https://site/shop/catalog/
https://site/shop/catalog/element/

tried it doesn't work

RewriteCond %{THE_REQUEST} ^/shop/shop/(.*)$ [NC]
RewriteRule ^(.*)$ /shop/%1 [R=301,L]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-06-10
@yous

Just replace %{THE_REQUEST} with %{REQUEST_URI}

RewriteCond %{REQUEST_URI} ^/shop/shop/(.*)$
RewriteRule ^(.*)$ /shop/%1 [R=301,L]

Or without RewriteCond
RewriteRule ^shop(/shop/.*) $1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question