D
D
Dmitry Khaperets2014-09-12 13:36:13
Apache HTTP Server
Dmitry Khaperets, 2014-09-12 13:36:13

Apache: how to make subdomains like folders?

There is a site.com domain. How can I make all *.site.com requests work as site.com/* (where "*" is any subdomain. for example: blog, about, account ...) ?
Tried like this:

<VirtualHost *:80>
    ServerAlias *.site.com
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^((.*)\.)site.com$
    RewriteRule ^/(.*) /%2/$1
    DocumentRoot /home/site.com/www
    <Directory /home/site.com/www>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

but it didn't work out

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
omcg, 2018-03-07
@omcg

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.site.com$
RewriteCond %{HTTP_HOST} ^((.*)\.)site.com$
RewriteRule ^/(.*) /%2/$1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question