Welcome to WebmasterWorld Guest from 54.196.175.173

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RewriteCond

or

     

gosman

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

10+ Year Member



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.

gosman

10:13 pm on Sep 12, 2011 (gmt 0)

10+ Year Member



Anyone?

g1smd

10:45 pm on Sep 12, 2011 (gmt 0)

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



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

lucy24

12:01 am on Sep 13, 2011 (gmt 0)

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



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?

g1smd

12:21 am on Sep 13, 2011 (gmt 0)

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



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.

gosman

9:21 am on Sep 13, 2011 (gmt 0)

10+ Year Member



Thanks guys

Worked a treat
 

Featured Threads

Hot Threads This Week

Hot Threads This Month