Answer the question
In order to leave comments, you need to log in
Redirect to htaccess, universal implementation - how to arrange it?
Good afternoon
I need to redirect to medomen.ru/subdomains/subsite when requesting subsite.mydomen.ru
I searched and searched, but found only options for specific folders.
And I need to be able to only create the folders I need without adding rules to each subdomain.
Those. 'subsite' - should be something like a variable
______________________________________
Thanks for the solution from Alexey S.:
1) Set up redirection of all subdomains to the root directory of the site (I did it through TP)
2) Set up .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9][-a-z0-9]+)\.primer\.ru(:80)?$ [NC]
RewriteCond %{HTTP_HOST} !^www\.primer\.ru
# RewriteCond %{DOCUMENT_ROOT}/Subdomains/%2 -d
RewriteRule ^(.*) /Subdomains/%2/$1 [E=SUBDOMAIN:%2,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]
Answer the question
In order to leave comments, you need to log in
You can’t do without setting up dns, you will need to register *.yoursite.ru on the main site and then all subdomains will break into one place
, but there already register htaccess to rewrite to the desired subfolder (how to make a 301 redirect to comments)
Setting up a transparent redirect in . htaccess
Requirement: You
must redirect all subdomains except www to a subfolder, but leave the path as it was in the request. That is, forum.primer.ru will be written in the browser address, and the content will be displayed from primer.ru/Subdomains/forum/
Solution:
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9][-a-z0-9]+)\.primer\.ru(:80)?$ [NC]
RewriteCond %{HTTP_HOST} !^www\.primer\.ru
# RewriteCond %{DOCUMENT_ROOT}/Subdomains/%2 -d
RewriteRule ^(.*) /Subdomains/%2/$1 [E=SUBDOMAIN:%2,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question