How to create multi subdomains from folders?

3

How to create multi subdomains with htaccess from folders, let's say I have my folders like this /folder1/folder2/ and I want my address to be so folder1.folder2.dominio.com

    
asked by Eddy Otsutsuki 29.06.2016 в 01:48
source

2 answers

2
RewriteEngine on

RewriteCond %{HTTP_HOST} subdominio.mipagina.com [NC]
RewriteRule ^(.*)$ http://www.mipagina.com/subcarpeta/$1 [L,NC,QSA]

The first and second lines (Options and RewriteEngine) serve to enable the rewriting of urls.

The following RewriteCond line will create a condition, which means that whenever the called url matches subdomain.mipagina.com it will be fulfilled and it will execute the following rule, but simply ignore it. [NC] serves not to distinguish between uppercase and lowercase and. They serve to escape the point since it is a special feature of the rewrites.

The last RewriteRule line will pick up any content that we send against that subdomain with (. *), that is, if we enter subdomain.mipagina.com/algomas, the algomas part will be saved as variable and we will include it later. The next part is the destination link $ 1, the subfolder we want to send it to. The $ 1 is used to place the variable that we have said before, so when loading the subdomain that I mentioned it would redirect it to link , so we could enter any subfolder and file that has been written in the browser automatically. Lastly [L, NC, QSA] means:

  • L = Last action (if it matches and redirects, it does not keep looking for more rules, it's not necessary)
  • NC = No Case Sensitive, does not distinguish between upper and lower case letters
  • QSA = Collect all query variables that we can send, that is, if we send? var = something, we will also send this to the new address
answered by 29.06.2016 / 08:37
source
3

I find it a bit complex to rewrite more than one subdomain, since you would need to replace them in the rewriteRule. by /

For a single subdomain, it would suffice:

RewriteEngine On
RewriteBase /

# No reescribimos directorios reales...
RewriteCond %{REQUEST_FILENAME} !-d
# ... ni archivos
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^([a-z0-9\.]+)\.dominio\.com$ [NC]
RewriteRule ^([^/]+)/?$ %1/$2 [QSA,L]

finally, this would serve for domain of type:

subd.domain.com -> <path_base>/subd
subd1.subd.domain.com -> <path_base>/subd1.subd

I hope it serves you

greetings

    
answered by 29.06.2016 в 11:06