Simple subdomain redirect

Using a single web hosting account to host multiple sites

Postby Cadish » Mon Mar 09, 2009 1:37 pm

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

Postby richardk » Tue Mar 10, 2009 12:41 pm

That's correct, so the problem should not be on the HTTP_HOST lines.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

Postby Cadish » Tue Mar 10, 2009 1:57 pm

test.example.com redirects to http://test.example.com/script.php?user ... quest_uri=

www.test.example.com redirects to http://www.test.example.com/script.php? ... quest_uri=

I don't know how to thank you for all this, man!!!
Cadish
 
Posts: 11
Joined: Tue Mar 03, 2009 4:45 am

Postby richardk » Wed Mar 11, 2009 10:27 am

It's working with QSA instead of R too?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Cadish » Wed Mar 11, 2009 10:34 am

No, I get an 500 Internal Server Error...
Cadish
 
Posts: 11
Joined: Tue Mar 03, 2009 4:45 am

Postby richardk » Wed Mar 11, 2009 11:23 am

Try replacing
Code: Select all
!^script\.php$

with
Code: Select all
!script\.php
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Cadish » Thu Mar 12, 2009 11:46 pm

No, this doesn't work. Only www.test.example.com redirects correctly.
test.example.com gives a 404.

Maybe, this is a very stupid solution, but this one works, except it's not silent...

Code: Select all
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ [NC]
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule ^ http://www.example.com/script.php?username=%1 [R=301,L]
Cadish
 
Posts: 11
Joined: Tue Mar 03, 2009 4:45 am

Postby richardk » Fri Mar 13, 2009 5:22 am

You could redirect test.example.com to www.test.example.com instead, try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Force www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Rewrite sub domains.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.([^\.]+)\.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 » Sun Mar 15, 2009 1:23 am

We're almost there :D

test.example.com redirects now to www.test.example.com/test/

It should be better if it just redirects to www.test.example.com

I've this code now, and it seems to work:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Force www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST} [R=301,L]

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


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

Postby richardk » Sun Mar 15, 2009 12:45 pm

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Force www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

because them test.example.com/something (and example.com/something) will redirect to www.test.example.com/something (and www.example.com/something).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

PreviousNext

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 15 guests

cron