D
D
Denis Bukreev2015-10-28 01:32:14
htaccess
Denis Bukreev, 2015-10-28 01:32:14

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

2 answer(s)
A
Alexey S., 2015-10-28
@denisbookreev

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]

(the commented out line checks for the existence of the domain folder before moving on, I'm fine with the 404 error so it's commented out)

S
ShamblerR, 2015-11-01
@ShamblerR

RewriteCond %{HTTP_HOST} !^www\.mydomen\.ru [NC]
RewriteCond %{HTTP_HOST} !^www\.(.*)mydomen\.ru [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.mydomen\.ru [NC]
RewriteRule ^(.*)$ http://mydomen.ru/subsite/%1$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