: 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
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?
More posts by @Deb1703797
2 Comments
Sorted by latest first Latest Oldest Best
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]
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.