Forum Moderators: phranque
Original thread:
[webmasterworld.com...]
I have since created a second subdomain on my site. However, the solution found in the thread above does not work with 2 subdomains (unless I am being impatient and my control panel has not implemented it). When I got to my subdomain URL (dev.example.com), it pulls up the same content that is found with the normal site (www.example.com) even thought I have an index.html file here www.example.com/dev/index.html.
Below is the .htaccess in full but first a little about what is going on and what I want to happen in the file.
I have my site:
www.example.com
I have a subdomain:
sub1.example.com
I have a folder I use as the root of my site:
www.example.com/0
I also have a staging directory that I allow access to and have .htpasswd applied via the control panel:
www.example.com/staging
What I am trying to do is implement a second subdomain for staging (ultimately removing the staging folder altogether and using dev in it's place):
dev.example.com
and further more, I would like to make folders to version my site to keep in syc with the main directory, and use as the root directory for the subdomain so in essence I would like:
www.example.com/dev/0 -> dev.example.com or dev/0.example.com -> dev.example.com
I know the above can be a bit confusing and I hope it comes across coherently. Thanks in advance for any and all insight.
Cheers!
Options +FollowSymLinks
RewriteEngine On
AddType x-mapp-php5 .php
#allows direct access to this subdomain -- sub1.example.com
#stops the mod re-write from happening on this folder
RewriteRule ^sub1/ - [L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ [www\.example\.com...] [L,R=301]
RewriteRule ^/sub1/(.*)$ [sub1.example.com...]
#allows direct access to this subdomain -- dev.example.com
#stops the mod re-write from happening on this folder
RewriteRule ^dev/ - [L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ [www\.example\.com...] [L,R=301]
RewriteRule ^/dev/(.*)$ [dev.example.com...]
#declares the base from which to start the rewrite
RewriteBase /
#sets the folder in which to make the 'base'
RewriteCond %{REQUEST_URI} !(0)
RewriteRule ^0/(.*)$ 0/$1/ [L]
#allows direct access to this directory
RewriteCond %{REQUEST_URI} !(staging/0)
RewriteRule ^staging/(.*)$ staging/0/$1/ [L]
#allows direct access to this directory
RewriteCond %{REQUEST_URI} !(examplesite)
RewriteRule ^examplesite(.*)$ examplesite/$1/ [L]
#sets the conditions.
RewriteCond %{REQUEST_URI} ^/*
RewriteCond %{REQUEST_URI} !(staging¦0¦examplesite¦sub1¦dev)
RewriteRule ^(.*)$ 0/$1 [L,NC]
#custom error pages.
errorDocument 400 /error/400.html
errorDocument 401 /error/401.html
errorDocument 403 /error/403.html
errorDocument 404 /error/404.html
errorDocument 500 /error/500.html
These two rules:
RewriteRule ^sub1/ - [L]
RewriteRule ^dev/ - [L]
Therefore, the subsequent 'sub11' and 'dev/' rules will never run for URL-paths starting with those two path-parts. It seems fairly obvious that this defeats two major functions in the code.
There's also an apparently-redundant copy of the domain canonicalization rule in there. As your code is currently structured, only the second one is 'safe' to use.
Anyway, the major problem with this code appears to be structural -- the logic and scope of the rules and their order needs some review and some work. Short of a major rewrite --which is not the purpose of this forum-- I can't offer much more.
Jim