Forum Moderators: phranque

Message Too Old, No Replies

Sending one IP to a specific page on the site

         

Shai

4:00 pm on Dec 3, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi All. I have a slight problem I need help with.

I have a strange IP address from a specific location in the UK which keeps hitting my site over and over again every day for the last few days now. I have created a specific page on my site and all I want to do is add a redirect to my htaccess code to redirect that IP to that page and that page only.

Is that possible?

I currently have

RewriteCond %{REMOTE_ADDR} ^11.11.11.111
RewriteRule .* http://www.example.com/suspicious-activity-from-your-ip-address [R=302,L]


However, when I try it with my ip address, I get an internal server error. Probably an infinite loop?

Any help appreciated.

penders

5:44 pm on Dec 3, 2014 (gmt 0)

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



Here's a clue... only redirect when they are not already on the page you want to redirect them to.

Demaestro

6:03 pm on Dec 3, 2014 (gmt 0)

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



Shai, what is happening is this

1) user comes to your site and requests a page (lets pretend it is /contact)
2) if user IP matches IP then they are redirect to /redirect.html
3) what happens here is we are back at step 1...

1) user requests a page (but this time it is /redirect.html)
2) if user IP matches IP then they are redirect to /redirect.html
3) what happens here is we are back at step 1... user requests a page (again /redirect.html)

and loop and loop we go... you want to another condition that says and page not /redirect.html

Add this condition
RewriteCond %{REQUEST_URI} !^/suspicious-activity-from-your-ip-address

Shai

7:22 pm on Dec 3, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks. That's what I thought but I have already tried that and it does not work.

RewriteCond %{REMOTE_ADDR} ^11.111.111.11
RewriteCond %{REQUEST_URI} !^http://www.example.com/suspicious-activity-your-ip-address
RewriteRule .* http://www.example.com/suspicious-activity-your-ip-address [R=302,L]


also tried it with relative paths just in case. Am I missing something? There are other redirects on the file could it be that they are interfering?

aakk9999

7:47 pm on Dec 3, 2014 (gmt 0)

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



REQUEST_URI is wrong. It should not have protocol nor domain name.

Shai

7:59 pm on Dec 3, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks aakk9999. It seems however that the reason it did not work is because it was conflicting with:

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


Added this:

RewriteCond %{REQUEST_URI} !index.php


and it now works perfectly.

Thanks everyone for helping.

lucy24

8:13 pm on Dec 3, 2014 (gmt 0)

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



RewriteCond %{REMOTE_ADDR} ^11.111.111.11

Make sure you escape all literal periods in the IP. In this specific case it will not lead to unwanted consequences, but even here there can be temporary errors:

IP 1 >> server says so far so good
IP 11 >> so far so good
IP 112 >> so far so good (because . matches any one character)
IP 112. >> server says Oh, oops, guess it isn't a match

Escape the period and the server will be out of there 1 step sooner.

RewriteCond %{REQUEST_URI} !^http://www.example.com/suspicious-activity-your-ip-address

The REQUEST_URI begins with / meaning "root of this domain".

wilderness

5:23 am on Dec 4, 2014 (gmt 0)

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



FWIW, if you've a custom 403, 404 and 410 than you also need to exclude those pages.
In addition, if you have a contact submission form (or image) than they need excluding as well.
I even exclude the TOS page.

The data on my website is a very, very small portion (less than 1%) of my widget materials. I find this a useful tool when a visitor is looking for something that is not active on my websites, however within my archives.