P
P
pr-Legolasov2019-07-23 13:40:22
htaccess
pr-Legolasov, 2019-07-23 13:40:22

Redirect for all subdomains to their folders?

Good afternoon!
It is necessary to set up a redirect without changing the url for all regional subdomains to folders located in the root directory of the main site with the same names (moscow.site.ru > site.ru/moscow), without writing their names in htaccess, but using some universal method .
The following code currently works:
RewriteCond %{HTTP_HOST} ^dzerzhinsk\.xn--80ajybdmjbd1a\.xn--p1ai$
RewriteCond %{REQUEST_URI} !/dzerzhinsk/
RewriteRule ^(.*)$ /dzerzhinsk/$1 [L]
and so for all subdomains, of which there are 157 pieces, I want to reduce htaccess every 100 times, is it possible to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-07-23
@pr-Legolasov

RewriteCond %{HTTP_HOST} ^(?>www\.|)([^.]+)\.xn--80ajybdmjbd1a\.xn--p1ai$
RewriteCond %1.%{REQUEST_URI} !^([^.]+)./\1/
RewriteRule ^(.*)$ /%1/$1 [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question