J
J
JustChrome2022-02-16 09:55:51
Apache HTTP Server
JustChrome, 2022-02-16 09:55:51

How to redirect from subfolders to subdomains?

I welcome everyone!
Need help, dug up a lot of information found, but did not understand the issue.

The URLs of the old version of the site looked like this:
domain.ru/spb/catalog
domain.ru/msk/catalog
, etc.

Now we decided to switch to subdomains and we need to get URLs like this:
spb.domain.ru/catalog
msl.domain.ru/catalog

I understand that you can "hook" on a part of the URL like this:

RewriteCond %{REQUEST_URI} ^/spb/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/rostov/(.*)$

But how to make a redirect from each to the corresponding subdomain and at the same time remove this piece from the final url, I can’t figure it out.

I would be grateful if someone could suggest a solution or a direction for a solution.
For example, how to write the received pieces of "/spb/" into variables and display these variables as a subdomain at least.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2022-02-16
@justchrome

RewriteCond %{HTTP_HOST}   ^(?:www\.)?domain\.ru$ [NC]
RewriteRule ^(spb|msk|rostov)/(.*)  http://$1.domain.ru/$2 [R=301,L]

Or so
RewriteCond %{HTTP_HOST}   ^(?:www\.)?domain\.ru$ [NC]
RewriteCond %{REQUEST_URI} ^/(msk)/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/(spb)/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/(rostov)/(.*)$ 
RewriteRule ^  http://%1.domain.ru/%2 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question