Forum Moderators: phranque

Message Too Old, No Replies

Help with directing specific domains to specific pages

         

Hatari

5:10 pm on Feb 9, 2011 (gmt 0)

10+ Year Member



Hi All,

Hope i have put this in the right place.

I would like to be able to redirect accesses from IP ranges **.**.**.**/24, or user agent yyy to either robots.txt if the GET is robots.txt or 403.shtml if it is anything else.

Something like this

IF IP = 64.24.155.00/24 OR Agent = "(compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR ; http/www.talktalk.co.uk/products/virus-alerts/)"

AND GET = http//broadbandadvice.org.uk/robots.txt

GOTO http//broadbandadvice.org.uk/robots.txt

ELSE

http//broadbandadvice.org.uk/403.shtml

Server in Linux

Help anyway I can do this?

Many thanks

Hatari

g1smd

6:37 pm on Feb 9, 2011 (gmt 0)

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



If you redirect a user to example.com/403.html the server will first return a 301 status code, and then a 200 OK status code as the page is shown.

The user will not be served a 403 status code at any point in the proceedings.

Hatari

11:44 pm on Feb 9, 2011 (gmt 0)

10+ Year Member



Maybe I have not made what I am trying to do clear.

Object to redirect certain IPs to either robots.txt if they have asked for robots.txt.

If the IP has asked for anything else then I want to redirect to 403.shtml

It an IF OR thing is that possible

Thanks

Hatari

wilderness

8:28 am on Feb 10, 2011 (gmt 0)

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



It an IF OR thing is that possible


Use multi-conditional criteria (RewriteCond; REMOTE_ADDR & REQUEST_URI).
Then add a RewriteRule line to robots.txt.

For your "OR" or NOT?
Duplicate the same multi-conditions, however Anchor the REQUEST_URI with a leading exclamation point that signifies NOT.
Change your RewriteRule to your 403.

Please keep in mind that although it functions as "you wish", it does NOT (as g1smd explained) provide a valid 403 header to the bot and/or requesting visitor.

jdMorgan

10:21 pm on Feb 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You do not "redirect to a 403 page." To do so is an error and it violates the HTTP protocol.

Instead, you directly invoke a server 403-Forbidden response and let the server supply a "403 page" along with the correct HTTP response code. If you have not already done so, you will need to configure the server to tell it what page to use. Example using mod_rewrite:

# Declare 403 error page
ErrorDocument 403 /403.shtml
#
# Forbid access to all pages except robots.txt and 403.shtml to the following IP addresses and ranges
RewriteCond %{REMOTE_ADDR} =192.168.0.10 [OR]
RewriteCond %{REMOTE_ADDR} ^10\.10\.0\. [OR]
RewriteCond %{REMOTE_ADDR} ^172\.100\.9[6-9]\. [OR]
RewriteCond %{REMOTE_ADDR} ^172\.100\.(1[01][0-9]|12[0-7])\.
RewriteRule !^(robots\.txt|403\.shtml)$ - [F]

The first RewriteCond uses an exact match: Only exactly 192.168.0.10 will be denied.
The second line uses a regular expression. Because the last octet of the address is not specified, all clients in the range from 10.10.0.0 through 10.10.0.255 will be denied.
The third RewriteCond denies access to clients from IP addresses in the range 172.100.96.0 through 172.100.99.255.
The last RewriteCond denies accress to clients in the IP address range of 172.100.100 through 172.100.127.255.

Another way to do this is by using mod_setenvif and mod_access:

# Declare 403 error page
ErrorDocument 403 /403.shtml
#
# Forbid access to all pages except robots.txt and 403.shtml to the following IP addresses and ranges
SetEnvif Request_URI "^(robots\.txt|403\.shtml)$" Allow_it
#
Order Deny,Allow
Deny from 192.168.0.10
Deny from 10.10.0.
Deny from 172.100.96.0/22
Deny from 172.100.100.0/22 172.100.104.0/21 172.100.112.0/20
Allow from env=Allow_it

Each "Deny from" line denies the same addresses as the RewriteConds above. Note the advantages of using regular-expressions matching in some cases, and CIDR notation in others.

Set the documentation for mod_rewrite, mod_setenvif, and mod_access for more information.

Jim