Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite subdomain and redirect

.htaccess coding

         

hershko

10:14 am on May 20, 2005 (gmt 0)

10+ Year Member



tried the following code to redirect users from invalidsubdomain.example.com to www.example.com/blog/invalidsubdomain but its not working. can someone point out the error?

thanx!
ohad

--------

RewriteEngine on
RewriteCond %{HTTP_HOST}!^(www\\.)?example\\.com [NC]
RewriteCond %{HTTP_HOST} ^(.*)\\.example\\.com [NC]
RewriteRule .* [example.com...] [R=301,L]

jdMorgan

2:48 pm on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remove the double backslashes for a start:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule .* http://www.example.com/blog/%1 [R=301,L]

Jim

hershko

8:45 pm on May 20, 2005 (gmt 0)

10+ Year Member



finally!

thanx, of course it would be something small...

hershko

9:15 pm on May 20, 2005 (gmt 0)

10+ Year Member



darn, spoke too soon.

its redirecting ALL subdomains, including valid ones.
i.e. forum.example.com used to go to www.example.com/forum/ but now its also being rewritten by the new htaccess code...

:(

how can i include some exceptions to what i have?

thanx again!
ohad

jdMorgan

9:30 pm on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> its redirecting ALL subdomains, including valid ones

I'm sorry... Exactly how do you define a "valid subdomain" and an "invalid subdomain"?

What information does the server have that you need to test?

Jim

hershko

9:37 pm on May 20, 2005 (gmt 0)

10+ Year Member



valid subdomains lead to subdirectories that i have already created i.e. mail.example.com and forum.example.com

invalid subdomains lead to user-created subdirectories that are created by my site
for example:
user1.example.com leads to www.example.com/blog/user1
user2.example.com leads to www.example.com/blog/user2

the code above is correctly directing the user-created subdomains to their appropriate subdirectories, but now its also redirecting my valid subdomains like mail and forum to:
www.example.com/blog/mail
and
www.example.com/blog/forum

argh! i think i have to separately specify all my valid subdomains...

jdMorgan

9:42 pm on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, add them to the first RewriteCond:

RewriteCond %{HTTP_HOST}!^[b]((www¦blog¦forum)\.)[/b]?example\.com [NC]

Change the broken pipe "¦" characters to solid pipe characters before use -- usually Shift-\ on the keyboard.

Jim

hershko

9:55 pm on May 20, 2005 (gmt 0)

10+ Year Member



whew, looks like i'm good .... for now...