Forum Moderators: phranque

Message Too Old, No Replies

another mod_rewrite question

         

sticker_sz

5:08 am on Feb 11, 2006 (gmt 0)

10+ Year Member



Hi everyone :)

I am trying to redirect visitors by HTTP_REFERER and GeoIP

I was using several months with the GeoIP redirection without any problems but when I added additional redirection for few domains in my httpd.conf than the servers started showing me this message only "Bad Request"

I noticed few things:

1)when I use the HTTP_REFERER redirection in .htaccess file on another domain witch doesn't include the GeoIP redirection in the httpd.conf file than everything works fine.

2)when I use the HTTP_REFERER redirection in .htaccess file on domain with GeoIP redirection in the httpd.conf file then the HTTP_REFERER redirection is not working.The server just pass the the HTTP_REFERER redirection in the .htaccess file

3)when I place both types of redirection in the httpd.conf then the server returns me BAD REQUEST

here are both types of redirection I am trying to run together

httpd.conf
=====================================
GeoIPEnable On
GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat
RewriteEngine On

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^KP$ [OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^KR$ [OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^TW$ [OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CN$ [OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^BR$

RewriteRule ^/index\.shtml /indexx.shtml [nc]
#################

RewriteCond %{HTTP_REFERER} ^http://.*domain1.*$ [OR]
RewriteCond %{HTTP_REFERER} ^http://.*domain2.*$ [OR]
RewriteCond %{HTTP_REFERER} ^http://.*domain3.*$ [OR]
RewriteCond %{HTTP_REFERER} ^http://.*domain4.*$

RewriteRule ^(.*)\.shtml$ indexx.shtml [nc]

jdMorgan

3:36 pm on Feb 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sticker_sz,

Welcome to WebmasterWorld!

Try simplifying this code and adding a RewriteCond to prevent looping in the second rule:


GeoIPEnable On
GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat
RewriteEngine On
#
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(KP¦KR¦TW¦CN¦BR)$
RewriteRule ^/index\.shtml$ /indexx.shtml [NC,L]
#
RewriteCond %{REQUEST_URI} !^/indexx\.shtml$
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain1\.com [OR]
RewriteCond %{HTTP_REFERER} ^http://.*domain2 [OR]
RewriteCond %{HTTP_REFERER} ^http://.*domain3 [OR]
RewriteCond %{HTTP_REFERER} ^http://.*domain4
RewriteRule \.shtml$ /indexx.shtml [NC,L]

Combining the geoip lookups using the "local OR" in RewriteCond will probably speed up your server, too.

Change all broken pipe characters "¦" above to solid pipes before use; Posting on this forum modifies the pipe characters.

Jim

sticker_sz

4:01 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



many thanks jdMorgan
the code you provided me works great :)