Configuring htaccess to use auto-subdomains

Task:

There is a website gid28.ru. You need to do this by url:

  1. blagoveshchensk.gid28.ru - opened the url www.gid28.ru/city/blagoveshchensk, or www.gid28.ru/city/28, for example.
  2. uniorextrim.gid28.ru - the url www.gid28.ru/promo/firma/969, well, or www.gid28.ru/promo was opened, and already the company itself, as I understand it, will have to be taken from the subdomain. Although, perhaps, you can somehow use this: uniorextrim.gid28.ru to get www.gid28.ru/promo/firm/uniorextrim?
  3. map.gid28.ru - opened the url map.gid28.ru (This subdomain is created manually via the hosting control panel)

I will throw off 500r on webmoney for a really competent answer and solution to this problem.

28.03.2014

So here's what I've come to...
Here is the file entry .htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} ^gid28.ru
RewriteRule (.*) http://www.gid28.ru/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?q=$0


RewriteCond %{HTTP_HOST} ^(.*)\.gid28\.ru$
RewriteCond %{HTTP_HOST} !^www\.gid28\.ru$
RewriteRule ^(.*)$ subdomains/index\.php

Now the difficulty is that the main domain I have with WWW. I can't figure out how to write a regular rule so that www.gid28.ru does not redirect, but subdomain.gid28.ru or www.subdomain.gid28.ru redirects.
Or maybe it stands for the main one domain take url without www?

I haven't quite figured out why we need flags (for example, [l,QSA] , etc.)

Author: cyadvert, 2014-03-26

1 answers

RewriteCond %{HTTP_HOST} !^www.gid28.ru [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).gid28.ru [NC]
RewriteRule ^(.*)$ subdomains/index\.php

I answer why I have www.sub.site.ru it worked fine, and sub.site.ru it didn't work. When I created the domain, I specified that the subdomains are located in the domain subdirectory. Accordingly in Nginx there was an entry that all urls of the type sub.site.ru sent to the root of the site/sub. That's what I didn't take into account, but this is how everything works.

 1
Author: makan, 2014-03-29 00:09:20