T
T
Timur Kalimullin2014-06-04 13:11:07
Domain name market
Timur Kalimullin, 2014-06-04 13:11:07

Automatic redirect of any subdomain to the domain name folder

Good afternoon,
to redirect a subdomain to a site folder, the name of which also matches the subdomain name, I use:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^subdomain\.mysite\.ru$
RewriteCond %{REQUEST_URI} !/subdomain/
RewriteRule ^(.*)$ /subdomain/$1 [L]

but there can be hundreds of such subdomains. How can this process be automated?
Get the name of the subdomain: RewriteCond %{HTTP_HOST} ^((.*)\.)mysite\.ru$
What should the subdomain be replaced with?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Kalimullin, 2014-06-04
@ZetRider

Working option:

RewriteEngine On
RewriteRule ^([a-zA-Z]+)/ - [L]
RewriteCond %{HTTP_HOST} ^(.*)\.mysite\.ru$
RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R,L]
RewriteCond %{HTTP_HOST} ^(.*)\.mysite\.ru$
RewriteRule (.*) %1/$1 [L,QSA]

This option didn't work.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.ru$
RewriteCond %{HTTP_HOST} ^((.*)\.)mysite.ru$
RewriteRule ^/(.*) /%2/$1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question