S
S
SergeyZlygostev2021-09-27 18:25:49
htaccess
SergeyZlygostev, 2021-09-27 18:25:49

How to make an htaccess 301 redirect from a subdomain to a folder of the same name on the main domain?

There is a construction that redirects from a subdomain (city) in English ( https://city.site.ru/en/ ) to a folder of the same name on the main domain ( https://site.ru/en/city/ ):
RewriteCond %{HTTP_HOST} ^city\.site\.ru$ [NC]
RewriteRule ^en\/$ https://site.ru/en/city/ [R=301,L]
The goal is to make the rule common to all subdomains (cities ), like:
RewriteCond %{HTTP_HOST} ^( moscow|novosib|.... #etc. pieces 50# )\.site\.ru$ [NC]
#depending on which city the user chose
RewriteRule ^ en\/$ https://site.ru/en/ city / [R=301,L]
#and here I stalled, how to get the part about the city from %{HTTP_HOST} RewriteCond and insert instead of "city" into the RewriteRule?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-09-27
@SergeyZlygostev

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(?>www\.|)(.+)\.site\.ru$ [NC]
RewriteRule ^en/$ https://site.ru/en/%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