T
T
Timur Kalimullin2017-07-30 23:22:09
htaccess
Timur Kalimullin, 2017-07-30 23:22:09

How to correctly create an htaccess redirect for different subdomains and domains?

Good afternoon,
The server hosts domains that are processed by one htaccess (refer to one folder with the site).
Previously, these domains were assigned subdomains of the form

mobile.sudmonain1.site 1 .ru
mobile.sudmonain2.site 1 .ru
mobile.sudmonain1.site 2 .ru

Now we decided to get rid of mobile and leave only the letter m .
What rule can implement this, given that the domains are different, but are processed by one htaccess?
Something like?
RewriteCond %{HTTP_HOST} ^(www\.)?mobile\.(.+) [NC]
RewriteRule ^(.*)$ http://m.%1/$1 [R=301,L]

The result should be a redirect to
m.sudmonain1.site 1 .ru
m.sudmonain2.site 1 .ru
m.sudmonain1.site 2 .ru

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2017-07-31
@shambler81

RewriteCond %{HTTP_HOST} ^(www\.|)mobile\(.+) [NC]
# domain with or without www select two groups before mobile and after
RewriteRule ^(.*)$ http://%1m%2/ $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