Forum Moderators: phranque
Here is my code:
Options +FollowSymLinks
RewriteEngine On
AddType x-mapp-php5 .php
#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 for a seperate domain
RewriteCond %{REQUEST_URI} !(joe)
RewriteRule ^joe(.*)$ joe/$1/ [L]
#allows direct access to this subdomain
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/subdomain/(.*)$ [subdomain.example.com...]
#sets the conditions.
RewriteCond %{REQUEST_URI} ^/*
RewriteCond %{REQUEST_URI} !(0¦1¦staging/0¦thoughts¦mobile¦joe¦subdomain)
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
There are several more tweaks needed, but these should not directly affect the problem.
Jim
The below updated .htaccess file is giving me server error. (500)
Options +FollowSymLinks
RewriteEngine On
AddType x-mapp-php5 .php
#declares the base from which to start the rewrite
RewriteBase /
#allows direct access to this subdomain
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RedirectRule 301 ^/subdomain/(.*)$ [subdomain.example.com...]
#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 for a seperate domain
RewriteCond %{REQUEST_URI} !(joe)
RewriteRule ^joe(.*)$ joe/$1/ [L]
#sets the conditions.
RewriteCond %{REQUEST_URI} ^/*
RewriteCond %{REQUEST_URI} !(0¦1¦staging/0¦thoughts¦mobile¦joe¦subdomain)
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
Jim
#sets the conditions.
#RewriteCond %{REQUEST_URI} ^/*
#RewriteCond %{REQUEST_URI} !(0¦1¦joe¦subdomain)
#RewriteRule ^(.*)$ 0/$1 [L,NC]
Everything works... sorta.
My server is set up as such:
www.example.com
/0
/1
/joe
/subdomain (this is the folder that the subdomain sets as it's root)
in my cpanel the subdomain.example.com is setting /subdomain as its destination
My site lives inside of /0 & /1.
When the above is commented out, my site runs off the root '/'
When it is not commented it runs off the set base folder '/0' or '/1' (depending on which I have it set to).
However, subdomain.example.com it says, "The page isn't redirecting properly"
I am so confused as to what is going on..
--- different subject ---
The second RewriteCond in your commented-out code should have prevented it from rewriting your subdomain unless the 'pipe' characters in your pattern are broken pipe "¦" characters, as always shown on this forum.
Be aware that any broken pipe character you see here (or copy from here) must be replaced by a solid pipe character before use; Your patterns won't work if that is not done.
See the second RewriteCond below. Those "¦" need to be replaced.
#sets the conditions.
#RewriteCond %{REQUEST_URI} ^/*
#RewriteCond %{REQUEST_URI} !(0¦1¦joe¦subdomain)
#RewriteRule ^(.*)$ 0/$1 [L,NC]
Jim
However, when going to my site sans 'www' it automatically goes to my sub domain. Not sure how to correct this. See below for what I have.
Options +FollowSymLinks
RewriteEngine On
AddType x-mapp-php5 .php
#allows direct access to this subdomain
#stops the mod re-write from happening on this folder
RewriteRule ^subdomain/ - [L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ [subdomain\.example\.com...] [L,R=301]
RedirectMatch 301 ^/ariel/(.*)$ [subdomain.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} !(example2)
RewriteRule ^example2(.*)$ example2/$1/ [L]
#sets the conditions.
RewriteCond %{REQUEST_URI} ^/*
RewriteCond %{REQUEST_URI} !(0¦1¦staging/0¦mobile¦example2¦subdomain)
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
Same issues still applies though, going to www.example.com and example.com do not take you to the same place.
http://example.com -> goes to [subdomain.example.com...]
http://www.example.com -> goes to http://www.example.com