Welcome to WebmasterWorld Guest from 50.17.5.36

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RewriteCond

or

     
4:08 pm on Sep 12, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts:383
votes: 0


I recently noticed my ip address was being indexed and I added the following code to my .htaccess


RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mysite\.tld$
RewriteRule (.*) [mysite.tld...] [R=301,L]


This worked fine at redirecting the IP addresses to the domain name. I have since added a secure domain at

[secure.mysite.tld...] however requests to this address are now being redirected [mysite.tld...]

Is there a way of adding and OR statement to the RewriteCond?

Like

RewriteCond %{HTTP_HOST} !^www\.mysite\.tld$ OR !^secure\.mysite\.tld$

Help much appreciated.
10:13 pm on Sept 12, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts:383
votes: 0


Anyone?
10:45 pm on Sept 12, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Use:
^((secure|www)\.example\.com)?$
12:01 am on Sept 13, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12714
votes: 244


Be careful with the OR. To achieve

host IS NEITHER {firstblahblah} NOR {secondblahblah}

you need

host IS NOT {firstblahblah} AND IS NOT {secondblahblah}

not

host IS NOT {firstblahblah} OR IS NOT {secondblahblah}

g1's version collapses both into a single statement except that, er, I think his keyboard choked on the !^ sequence again.

Tangential query: Are there situations where the HTTP_HOST is nothing?
12:21 am on Sept 13, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Err, yeah. I told you that was my most common code typo.

!^((secure|www)\.example\.com)?$


HTTP_HOST is blank when it is a pure HTTP/1.0 request. HTTP/1.0 didn't include the HOST header.
9:21 am on Sept 13, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 7, 2003
posts:383
votes: 0


Thanks guys

Worked a treat
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members