xyz.dom.com --> dom.com/app/?n=xyz

Using a single web hosting account to host multiple sites

xyz.dom.com --> dom.com/app/?n=xyz

Postby john2007 » Tue Oct 31, 2006 12:37 pm

Hello

So I'm trying to write xyz.dom.com --> dom.com/app/index?n=xyz
or in the case of:
xyz.dom.com/something?stuffstuff dom.com/app/something?stuffstuff&n=xyz

But I seem to be failing miserably

# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]

# Extract (required) subdomain (%1), and first path element (%3), discard
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ([^.]+)\.dom\.com(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element stop recursion
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]


# Rewrite to /subdomain/path
RewriteRule ^(.*) /app/%1/$1 [L]


I get stuck in some sort of modrewrite loop..

Any help would MUCH be appreciated.
Thanks in advance.
john2007
 
Posts: 6
Joined: Tue Oct 31, 2006 12:31 pm

Postby richardk » Tue Oct 31, 2006 2:17 pm

All the sub domains point to the main document root, right?
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

Postby john2007 » Tue Oct 31, 2006 3:30 pm

Thanks that is much help, and does 50% of what I want it to do.

But it still doesn't handle if someone goes to xyz.dom.com/afile?aparm=aval it rewrites it to dom.com/app/index?n=xyz&aparm=aval

When it should be doing dom.com/app/afile?n=xyz&aparm=aval

I'm having trouble forming the last line..
john2007
 
Posts: 6
Joined: Tue Oct 31, 2006 12:31 pm

Postby richardk » Tue Oct 31, 2006 3:34 pm

Try:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST}  !^(www\.domain\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^$ /app/index?n=%1 [QSA,L]

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

Postby john2007 » Tue Oct 31, 2006 6:25 pm

Much thanks, you are fast, but now it seems to just get stuck in an max redirect detected loop if trying to do xyz.dom.com/afile?aparm=aval


Thanks again! :)
john2007
 
Posts: 6
Joined: Tue Oct 31, 2006 12:31 pm

Postby richardk » Wed Nov 01, 2006 7:45 am

Much thanks, you are fast, but now it seems to just get stuck in an max redirect detected loop if trying to do xyz.dom.com/afile?aparm=aval

Try replacing this !^app/index$, with !^app(/.*)?$. If that doesn't work try replacing the last section with
Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{HTTP_HOST}  !^(www\.domain\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ /app/$1?n=%1 [QSA,L]


Or this:
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST}  !^(www\.domain\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ /app/$1?n=%1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby john2007 » Thu Nov 02, 2006 6:03 am

Much thanks that worked as needed :)
john2007
 
Posts: 6
Joined: Tue Oct 31, 2006 12:31 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 54 guests

cron