Linces Marques
Linces Marques

Reputation: 684

Redirect subdomain to a specific directory

I need to redirect a subdomain to a specific folder on hosting.

Example:

store.mydomain.com display content from: mydomain.com/store

support.mydomain.com display content from: mydomain.com/support

But I don't know how to do that, I don't know if I do it for DNS records, e.g. "CNAME", or if I do it via Apache, adding the "a2ensite" subdomain, or ".htaccess".

If it's via .htaccess, how do i access mydomain.com/store via store.mydomain.com?

I even tried to do it by adding the subdomain via apache. But without success.

Like the .conf file below:

<VirtualHost *: 80>
    ServerName store.mydomain.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/mydomain.com/store

    <Directory /var/www/html/mydomain.com/store>
        Options -Indexes + FollowSymLinks
        AllowOverride All
    </Directory>

#LogLevel info ssl: warn

ErrorLog /var/www/html/mydomain.com.br/store/error.log
CustomLog /var/www/html/mydomain.com/store/access.log combined
</VirtualHost>

I have full access to the vps host. My main domain has already set up and is working perfectly.

So I think this should be done via .htaccess, right? But how?

I know it's a very simple question, but I don't have much experience with .htaccess.

Thank you

Upvotes: 1

Views: 654

Answers (1)

Razvan Cristea
Razvan Cristea

Reputation: 184

Maybe you can try using Alias:

<VirtualHost *:80>
    ServerName domain.com
    DocumentRoot /var/www/html/domain.com/
    Alias /store /var/www/html/domain.com/store

Upvotes: 1

Related Questions