Mod rewrite with sub domains

Using mod_rewrite to handle various content issues

Mod rewrite with sub domains

Postby poizn99 » Wed Jan 02, 2008 5:43 am

Hi all

We have recently implemented sub domains as part of our site. So to access each of our clients pages on our site, you would go to http://client.oursite.com.
I also got a few other rules to force www, if there is no sub domain, and any of the sub domain pages are handled by one script.
The rules that I used to get that working are as follows

Code: Select all
# Forcing no sub domain to WWW. eg: site.com -> www.site.com
RewriteCond %{HTTP_HOST} ^([-a-z0-9_]+\.[-a-z0-9_]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

# Rules for checking for a sub domain
RewriteCond %{HTTP_HOST} !^www\.[-a-z0-9_]+\.[-a-z0-9_]+$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.[-a-z0-9_]+\.[-a-z0-9_]+$ [NC]
RewriteRule ^$ /sub_domain_pages/sub_domain_page.php?listing=%1 [QSA,L]

# Rule for writing non listing pages sub domain back to WWW
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.[-a-z0-9_]+\.[-a-z0-9_]+$ [NC]
RewriteCond %{HTTP_HOST} ^.+\.([-a-z0-9_]+\.[-a-z0-9_]+)$ [NC]
RewriteRule !^sub_domain_pages/sub_domain_page\.php$ http://www.%1%{REQUEST_URI} [R=301,L]


All works well and good there, but if I try something like this http://client.oursite.com/description, I get a 404 error ;(

To give a little background, each of the clients we load on have a few different sections they need to display. So I created some tab, you click on the tab, and bam you go there, but I got to make it a nice pretty URL ;)

Does anyone know what im doing wrong?
Can anyone help?

Thanks in advance ;)
poizn99
 
Posts: 8
Joined: Tue Jul 31, 2007 11:57 pm

Postby richardk » Wed Jan 02, 2008 2:44 pm

^$ probably needs to be .*
Last edited by richardk on Thu Jan 03, 2008 10:18 am, edited 1 time in total.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby poizn99 » Thu Jan 03, 2008 1:23 am

Cool ill keep that in mind and try it out ;)
poizn99
 
Posts: 8
Joined: Tue Jul 31, 2007 11:57 pm

Postby poizn99 » Fri Jan 04, 2008 4:46 am

Hey cool that pretty much worked, you were on the right track.

Thanks
poizn99
 
Posts: 8
Joined: Tue Jul 31, 2007 11:57 pm


Return to Content

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron