homepage Welcome to WebmasterWorld Guest from 54.166.173.147
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
RewriteCond
or
gosman




msg:4361444
 4:08 pm on Sep 12, 2011 (gmt 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

https://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




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

Anyone?

g1smd




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

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




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

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




msg:4361669
 12:21 am on Sep 13, 2011 (gmt 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.

gosman




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

Thanks guys

Worked a treat

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved