Forum Moderators: phranque

Message Too Old, No Replies

Redirect some URLs from subdomain to root

         

clickfire

5:10 am on Aug 28, 2011 (gmt 0)

10+ Year Member



I am trying to redirect a few URLs from a subdomain to their respective root domain locations with the remaining subdomain URLs going to a directory on the root. I thought this would work but it's not. I'm stumped. Anyone see the light?

# Move good news subdomain urls to respective www locations
RewriteEngine On
RewriteRule news.clickfire.com/blah/123/$ http://www.clickfire.com/blah/ [R=301,L]

# Everything else on news subdomain go to root/viewpoints/news/
RewriteCond %{HTTP_HOST} ^news.clickfire.com$
RewriteRule ^(.*)$ http://www.clickfire.com/viewpoints/news/$1 [R=301,L]

lucy24

5:52 am on Aug 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Were your two Rules written by different people? The first Rule doesn't work because it can't work:

RewriteRule news.clickfire.com {et cetera}

The "pattern" part of a Rewrite only looks at the part of the address after the (sub)domain (and before the query string, if any). If you need to do something within a specific subdomain, you need a RewriteCond like the one accompanying the second Rule.

clickfire

7:02 am on Aug 28, 2011 (gmt 0)

10+ Year Member



I just pulled that first rule out of another htaccess file. I tried sticking some conditions in there but couldn't get anything to work. Any guess as to the what the RewCond should look like?

g1smd

7:47 am on Aug 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your first rule is good if you are redirecting
http://news.clickfire.com/something/news.clickfire.com/blah/123/
to a new URL. That is what you have coded it to do. RewriteRule sees only the path part of the request, not the domain name.

In the
RewriteCond
of the second rule you should escape the literal periods.