site Search:


 
    All Forums Hot Topics Gallery






how-to block ads


 
Search Topic:
Uniqs:
655
Share Topic
Posting?
Post a:
Post a:
Links: ·How To Get Noticed ·Web Monks FAQ ·Webhosting FAQ ·Posting Code ·How To Post ·Webhosting forum
AuthorAll Replies


Nordy

join:2007-10-20

RewriteRule failing when using HTTP_HOST

I did this rule which I hoped will redirect all users who try to access a .php file who are not from our host (since HTTP_REFERRER can be blank). But it wont work.

RewriteCond %{HTTP_HOST} !^localhost[NC]
RewriteRule \.(php)$ http://www.google.com [NC,R,L]
 
Over here, If : the host is not localhost, and the page extension is .php, send the user away

But thing is, even if the host "is" localhost, it'll send the user away.

My HTTP_HOST is localhost when i do this:

<?php
 
echo $_SERVER['HTTP_HOST']; //Gives me "localhost"
 
?>
 

Can u help me do this right?


state
stress magnet
Premium,Mod
join:2002-02-08
Purgatory
kudos:6

You need to lose the conditional arguments on the RewriteCond line. Try this:

RewriteCond %{HTTP_HOST} !^localhost$
RewriteRule \.(php)$ http://www.google.com [NC,R,L]
 


Nordy

join:2007-10-20

Wow! That actually worked. I guess Apache was returning the HTTP_HOST in uppercase or mixed case.

But does this mean I'll have to remove conditions for other rules too?
Like:

RewriteCond %{HTTP_REFERER} !^$  
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]  
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain2.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://www.localhost.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://www.google.com [NC,R,L]
 

I've not yet tested this on a server.
Thank you for helping with this.


state
stress magnet
Premium,Mod
join:2002-02-08
Purgatory
kudos:6
Host:
Webhosting
Android
Sonic.net
Washington & Balti..
UK Chat

The 'no case' statements shouldn't be necessary since it's a domain name which is lowercase. The problem you had before was the space missing between your expression and the NC flag. You can leave them in, or remove them, shouldn't really matter in this case.


Wednesday, 22-May 09:37:18 Terms of Use & Privacy | feedback | contact | Hosting by nac.net - DSL,Hosting & Co-lo
over 13.5 years online © 1999-2013 dslreports.com.
Most commented news this week
Hot Topics