Use .htaccess to configure subdomains serve content from folders rather than from the root domain
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, subdomain, multiple-domains, , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :Here is site http://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/(.*)$ http://brisbane.glassnow.com.au/$1 [L,R=301]
RewriteCond %HTTP_HOST ^www.glassnow.com.au
RewriteRule ^sunshinecoast/(.*)$ http://sunshinecoast.glassnow.com.au/$1 [L,R=301]
RewriteCond %HTTP_HOST ^www.glassnow.com.au
RewriteRule ^goldcoast/(.*)$ http://goldcoast.glassnow.com.au/$1 [L,R=301]
# redirect from non-www to www
RewriteCond %HTTP_HOST ^glassnow.com.au$ [NC]
RewriteRule ^(.*)$ http://www.glassnow.com.au/$1 [R=301,L]
RewriteRule ^index.html$ / [R=301,L]
RewriteRule ^(.*)/index.html$ /$1/ [R=301,L]
RewriteCond %REQUEST_FILENAME !-d
RewriteCond %THE_REQUEST ^GET /[^?s]+.html
RewriteRule (.*).html$ /$1/ [L,R=301]
RewriteCond %REQUEST_FILENAME !-d
RewriteRule (.*)/$ $1.html [L]
# Remove trailing slash:
RewriteRule (.*)/$ $1 [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?
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 www.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.
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/$1 [L]
RewriteCond %HTTP_HOST ^goldcoast.glassnow.com.au$
RewriteRule (.*) /goldcoast/$1 [L]
RewriteCond %HTTP_HOST ^sunshinecoast.glassnow.com.au$
RewriteRule (.*) /sunshinecoast/$1 [L]
Comments
Post a Comment