Simple subdomain redirect

Using a single web hosting account to host multiple sites

Simple subdomain redirect

Postby Cadish » Tue Mar 03, 2009 5:22 am

Hi,

I want to redirect a subdomain and am using this code now:

Code: Select all
Options +FollowSymLinks
RewriteEngine On
# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ /script.php?username=%2&request_uri=$1 [QSA,L]


Now, only www.user.domain.com redirects. I also want user.domain.com to redirect. How can I achieve this?

Thanks a lot in advance!! I'm searching for this for a couple of days now...
Cadish
Cadish
 
Posts: 11
Joined: Tue Mar 03, 2009 4:45 am

Postby richardk » Tue Mar 03, 2009 3:19 pm

What happens when you go to user.example.com?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Cadish » Wed Mar 04, 2009 12:12 am

I get a 404...

Cadish
Cadish
 
Posts: 11
Joined: Tue Mar 03, 2009 4:45 am

Postby richardk » Wed Mar 04, 2009 12:33 pm

It should match that rule. Do you have any other rules?

If you put the following in your .htaccess file
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule Google http://www.google.com/? [NC,R,L]

and go to user.example.com/Google do you get redirected. Are you sure those sub domains are going to that directory?

Also try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.([^\.]+)\.example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /script.php?username=%1&request_uri=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Cadish » Thu Mar 05, 2009 12:08 am

Thanks for the great effort!!

Your first script with google works. If I go to user.example.com/Google , it redirects.

The second script doesn't work... :(
Cadish
 
Posts: 11
Joined: Tue Mar 03, 2009 4:45 am

Postby richardk » Thu Mar 05, 2009 11:28 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /script.php?username=%1&request_uri=$1 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /script.php?username=%1&request_uri=$1 [QSA,L]

And
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/script\.php$ [NC]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.([^\.]+)\.example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /script.php?username=%1&request_uri=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Cadish » Fri Mar 06, 2009 12:06 am

Still the same :/

Maybe it has something to do with my host or the settings? :-?
Cadish
 
Posts: 11
Joined: Tue Mar 03, 2009 4:45 am

Postby richardk » Sun Mar 08, 2009 7:30 am

Have you asked your host about it?

Try the following in your .htaccess file
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule test http://www.example.com/?%{HTTP_HOST} [NC,R,L]

and going to /test. What URL go you get redirected to (what is %{HTTP_HOST} replaced with)?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Cadish » Mon Mar 09, 2009 4:21 am

I'm redirected to http://www.example.com/?www.example.com

Thanks for your patience!!

PS I will ask my host about this...
Cadish
 
Posts: 11
Joined: Tue Mar 03, 2009 4:45 am

Postby richardk » Mon Mar 09, 2009 6:55 am

For example.com/test or user.example.com/test? user.example.com/test is the important one (i should have specified that).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 2 guests

cron