Mobile app version of vmapp.org
Login or Join
Deb1703797

: Use .htaccess to configure subdomains serve content from folders rather than from the root domain Here is site http://www.glassnow.com.au/ With 3 subdomains: brisbane.glassnow.com.au goldcoast.glassnow.com.au

@Deb1703797

Posted in: #Htaccess #MultipleDomains #Subdomain

Here is site www.glassnow.com.au/ With 3 subdomains:


brisbane.glassnow.com.au
goldcoast.glassnow.com.au
sunshinecoast.glassnow.com.au


Here is htaccess

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.glassnow.com.au
RewriteRule ^brisbane/(.*)$ brisbane.glassnow.com.au/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www.glassnow.com.au
RewriteRule ^sunshinecoast/(.*)$ sunshinecoast.glassnow.com.au/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www.glassnow.com.au
RewriteRule ^goldcoast/(.*)$ goldcoast.glassnow.com.au/ [L,R=301]


# redirect from non-www to www
RewriteCond %{HTTP_HOST} ^glassnow.com.au$ [NC]
RewriteRule ^(.*)$ www.glassnow.com.au/ [R=301,L]


RewriteRule ^index.html$ / [R=301,L]
RewriteRule ^(.*)/index.html$ // [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET /[^?s]+.html
RewriteRule (.*).html$ // [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ .html [L]

# Remove trailing slash:
RewriteRule (.*)/$ [L]

# Now test without the trailing slash:
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule . %{REQUEST_FILENAME}.html [QSA,L]


<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
<ifModule mod_headers.c>
Header unset ETag
</ifModule>
FileETag None


Problem is that any of those subdomains points not to its directory but to the root folder. How to configure it correctly?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Deb1703797

2 Comments

Sorted by latest first Latest Oldest Best

 

@Heady270

richhallstoke's for configuring virtual hosts is usually the easiest approach. If for some reason you don't have access to configuration to let you do that, it can be done in .htaccess. Additional rewrite rules would be needed:

RewriteCond %{HTTP_HOST} ^brisbane.glassnow.com.au$
RewriteRule (.*) /brisbane/ [L]

RewriteCond %{HTTP_HOST} ^goldcoast.glassnow.com.au$
RewriteRule (.*) /goldcoast/ [L]

RewriteCond %{HTTP_HOST} ^sunshinecoast.glassnow.com.au$
RewriteRule (.*) /sunshinecoast/ [L]

10% popularity Vote Up Vote Down


 

@Martha676

I think the problem here is not to do with your .htaccess redirections, but to do with your VirtualHost configurations in Apache's httpd.conf configuration file - this is how Apache knows which folder to direct requests to for processing.

# Default Site - Blank
<VirtualHost *.80>
ServerName localhost
DocumentRoot /var/www/default
</VirtualHost>

# Parent Website
<VirtualHost *:80>
ServerName glassnow.com.au
ServerAlias glassnow.com.au DocumentRoot /var/www/glassnow-www
</VirtualHost>

# Brisbane Website
<VirtualHost *:80>
ServerName brisbane.glassnow.com.au
DocumentRoot /var/www/glassnow-brisbane
</VirtualHost>

# Gold Coast Website
<VirtualHost *:80>
ServerName goldcoast.glassnow.com.au
DocumentRoot /var/www/glassnow-goldcoast
</VirtualHost>

# Sunshine Coast Website
<VirtualHost *:80>
ServerName sunshinecoast.glassnow.com.au
DocumentRoot /var/www/glassnow-sunshinecoast
</VirtualHost>


Your respective webroot folders would then be those as defined with the DocumentRoot directives for each VirtualHost.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme