Redirect subdomains to a folder on the main domain


/ Published in: Apache
Save to your folder(s)

There is a domain: domain.ru
There are subdomains subdomain.domain.ru and forum.domain.ru
domain.ru is configured as a host and is located in the folder ... / www / domain /
Subdomains are aliases of the main domain - i.e. lead to the same folder ... / www / domain /
Idea: make subdomains refer to folders, inside the main domain folder, i.e.
subdomain.domain.ru -> ... / www / domain / sd_subdomain / subdomain /
forum.domain.ru -> ... / www / domain / sd_subdomain / forum /
Here is what you need to register in .htaccess


Copy this code and paste it in your HTML
  1. RewriteEngine On
  2. RewriteBase /
  3.  
  4. RewriteCond %{HTTP_HOST} !^www\.
  5. RewriteCond %{HTTP_HOST} (.*)\.domain\.ru
  6. RewriteCond $1 !^sd_
  7. RewriteRule (.*) /sd_subdomain/%1/$1 [L]

URL: http://backnet.ru/2014/04/29/redirekt-poddomenov-v-papku-na-osnovnom-domene/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.