rewrite a root level subdomain, but exclude subsequent pages

Using a single web hosting account to host multiple sites

rewrite a root level subdomain, but exclude subsequent pages

Postby jntwebdesigns » Thu Jul 16, 2009 1:33 pm

I have a site that I am trying to redirect subdomains to the main site with a user variable, like this:

Code: Select all
RewriteCond %{HTTP_HOST} ([^\.]+).mysite.(.*)
RewriteCond %{HTTP_HOST} !^exclude.mysite.(.*)
RewriteCond %{HTTP_HOST} !^www.mysite.(.*)
RewriteRule ^(.*)$ index.php?u=%1 [L,NC]


This works fine, so http://user.mysite.com goes to www.mysite.com/index.php?u=user

But, subsequent pages all go back to the index.php?u=user, so other page accesses do not work, ie:

http://user.mysite.com/register.php
http://user.mysite.com/index.php?m=module_name

and so on...
jntwebdesigns
 
Posts: 3
Joined: Thu Jul 16, 2009 1:23 pm

Postby richardk » Thu Jul 16, 2009 2:10 pm

Because ^(.*)$ matches every path. ^$ will only match requests to /.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(exclude|www)\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^$ /index.php?u=%1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jntwebdesigns » Thu Jul 16, 2009 2:23 pm

Yes, worked perfectly. But now as that works and I go thru, I see another issue. When a user logs out, they are redirected to:

http://demo.mysite.com/index.php

and then no user is captured (no index.php?u=user), so... for the index, is there a way to keep the base index.php in the rewrite loop, but not ones with variables, such as index.php?m=module?

Thanks so much.
jntwebdesigns
 
Posts: 3
Joined: Thu Jul 16, 2009 1:23 pm

Postby richardk » Thu Jul 16, 2009 3:30 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# An empty query string.
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^(exclude|www)\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(index\.php)?$ /index.php?u=%1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Re: rewrite a root level subdomain, but exclude subsequent pages

Postby jntwebdesigns » Mon Aug 16, 2010 9:05 am

I am having a similar issue with rewriting some queries and subsequent pages are captured by the rewrite

I have pages rewritten like:

http://www.site.com/los-angeles-ca/deals/

and the rewite looks like:
[code]
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?location=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?location=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?page=$2&location=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?page=$2&location=$1
[/code]

This works fine, but then pages in subfolders like:

http://www.site.com/user/images/image.jpg do not show because it is trying to rewrite the URL.
jntwebdesigns
 
Posts: 3
Joined: Thu Jul 16, 2009 1:23 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 20 guests

cron