F
F
FANTASANTA2020-09-08 19:03:00
htaccess
FANTASANTA, 2020-09-08 19:03:00

How to redirect from /ru to without /ru in htaccess?

Because of Laravel, I haven’t encountered htaccess for a long time, now I can’t understand where I’m making a mistake.

I need to make a 301 redirect like this:

site.ru/ru -> site.ru/ 
site.ru/ru/path -> site.ru/path


I write htaccess code in mod_rewrite section:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ru/(.*)$ https://%1/$1 [R=301,L]


Links like site.ru/path and site.ru/ru/path - open the same content in Russian, respectively, the robots indexed the links as duplicates. You need to set up a redirect from / ru to without / ru

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dodo512, 2020-09-08
@FANTASANTA

RewriteRule ^ru(?:/(.*))?$ /$1 [L,R=301]
Append immediately after RewriteEngine On

V
Viktor Taran, 2020-09-08
@shambler81

RewriteRule ^ru(.*)$ /$1? [L,R=301]

M
Mikhail Borisov, 2020-09-10
@valickSerjGe

RewriteRule ^ru(.*)$ /$1? [L,R=301]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question