Subdomain to script as parameter

Using a single web hosting account to host multiple sites

Subdomain to script as parameter

Postby nf » Mon Jan 05, 2009 10:38 am

Dears!

In fact I've found example to my question (here: viewtopic.php?p=15046#15046) but still have problems with passing correctly USER parameter so below there's my question.

I want to redirect when user inputs in a browser the address in one of such ways:
Code: Select all
www.USER.domain.com
USER.domain.com


to
Code: Select all
domain.com/script.php?id=USER



Please help.
Regards!
nf
 
Posts: 12
Joined: Thu Dec 04, 2008 6:26 am

Postby richardk » Mon Jan 05, 2009 12:16 pm

What problem are you having?
What mod_rewrite have you tried?
Have you set the DNS for the sub domains?
Is your server configured to send the requests to the correct directory?

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule ^$ /script.php?id=%2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nf » Mon Jan 05, 2009 12:33 pm

[b]Thank you! This example works perfect![/b]
Before I had a problem for which I have no clue - just parameter was not posted to script properly.
nf
 
Posts: 12
Joined: Thu Dec 04, 2008 6:26 am

second domain in the same folder

Postby nf » Mon Jan 05, 2009 1:04 pm

One more question.

As we are living in EU we sometimes use two domains for the same web service. How to add another domain as simple copying doesn't work:

Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.ANOTHERdomain\.EU$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.ANOTHERdomain\.EU$ [NC]
RewriteRule ^$ /script.php?id=%2 [QSA,L]


This works perfect for redirecting for 1st but gives error "Address Not Found" when we type 2nd one.
nf
 
Posts: 12
Joined: Thu Dec 04, 2008 6:26 am

Postby richardk » Mon Jan 05, 2009 5:58 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.(example\.com|example\.net)$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.(example\.com|example\.net)$ [NC]
RewriteRule ^$ /script.php?id=%2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nf » Tue Jan 06, 2009 1:05 am

Address
Code: Select all
USER.example.net
gives error #502 - bad gateway.
The error is only for parked domains and for primary domain it works fine.
Primary and parked domains all have wildcard subdomain (*.example.com and *.example.net) set.
Of course parked domains itself (without USER.) works fine.
nf
 
Posts: 12
Joined: Thu Dec 04, 2008 6:26 am

solved!

Postby nf » Tue Jan 06, 2009 10:17 am

seems that it was enough to add at the very end:
Code: Select all
RewriteRule .* - [L]
nf
 
Posts: 12
Joined: Thu Dec 04, 2008 6:26 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 25 guests

cron