Forum Moderators: phranque

Message Too Old, No Replies

mod geoip not working with htaccess

mod_geop is installed but not working with htaccess

         

phparion

6:16 am on Jun 5, 2007 (gmt 0)

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



Hi

I have installed mod_geoip and have confirmed its installation with small php code

echo $_SERVER['GEOIP_COUNTRY_CODE'];

and it does show country code e.g (PH)

but when I try the following in my htaccess it makes no affect on the site

RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^PH$
RewriteRule ^(.*) http://www.example.com/second.html [R=301,L]

can anybody guide me please how to make this work with htaccess? I want to redirect all Philippines users to second.html page

many thanks

benevolent001

6:29 am on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code seems correct did you have

GeoIPEnable On
GeoIPDBFile GeoIP.dat

lines in htaccess file?

Please can you help me in installing mod geoip?

phparion

6:47 am on Jun 5, 2007 (gmt 0)

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



Google Search Have Many Tutorials [google.com.pk]

I have placed this in my htaccess now

GeoIPEnable On
GeoIPDBFile GeoIP.dat

RewriteEngine On
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^PH$
RewriteRule ^(.*) http://www.example.com/second.html [R=301,L]

but still no affect

the file GeoIP.dat exists in root folder where my htaccess exists. I guess geoip is working because as I told before my php code picks the country code from the $_SERVER array correctly

can anybody help please?

[edited by: jdMorgan at 1:12 pm (utc) on June 5, 2007]
[edit reason] Link format repair [/edit]

phparion

8:33 am on Jun 5, 2007 (gmt 0)

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



Additionally, when I use phpinfo() i can see the following info

Apache Environment

VariableValue
GEOIP_COUNTRY_CODE PH
GEOIP_COUNTRY_NAME Philippines

but when I SSH client's server and open

vi /etc/httpd/conf/http.conf

I do not see anything like

<IfModule mod_geoip.c>

or anything else where I can see if the mod_geoip is enabled.

so should I call upon my customer's Server Admin to take any measures or the problem resides in my htaccess?

jdMorgan

1:16 pm on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are on Apache 1.x, be sure that you have loaded mod_geoIP *after* mod_rewrite. On Apache 1.x, modules are executed in the reverse order of the LoadModule list, and you must be sure that mod_geoIP runs before mod_rewrite in order to use it in an .htaccess context.

This is true of any module, whether it's PHP or geoIP, and this behaviour *is* documented at Apache.

Jim

phparion

6:22 pm on Jun 5, 2007 (gmt 0)

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



I have checked /etc/httpd/conf/http.conf file and there is no mod_geoip entry in this file neither within ifmodule tags or for LoadModules ...

however in the output of phpinfo() under Apache Environment I can see the country code and name etc so I am not sure if mod_geoip is working properly. Does anyone know how can I check that mod_geoip is working in the desired manner?

or any changes I should ask server admin to make in the http.conf to make the mod_geoip working properly?

thanks

phparion

7:43 am on Jun 6, 2007 (gmt 0)

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



still banging my head with the task :)

now I found yet another problem... I reinstalled mod_geoip from scratch with edited httpd.conf myself to make sure everything is right on the server

the htaccess, however, is making no affect to the site.. even if write any wrong code even in the htaccess under the root directory of the site the site doesn't give 500 error which it should.

does anyone has experience to deal with this situation to make the htaccess to affect the website?

thanks

phparion

2:08 pm on Jun 6, 2007 (gmt 0)

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



ok I fixed it with direct entries in httpd.conf virtual host section however I am not happy ....

Can any apache pro guide me that why htaccess file was not affecting the website despite the htaccess was in the domain root directory where the index.html page was?

and how can I make an htaccess to work with the directory if tracked in the same kinda situation in the future.

I desperately want to learn this for my knowledge.

many thanks

benevolent001

2:45 pm on Jun 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i had similar situation once when htaccess file was not excuted in the folder i wanted , i contacted my hosting team and they said the folder didnt had permissions to excute htaccess file , may be this is also your case although very remote chances are there for this error

jdMorgan

5:05 pm on Jun 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I assumed you had previously-working rewrite rules.

For later readers, it is a good idea to start simple, test, and then move on to complex implementations a step at a time. For example, here's a good 'first rule' to put on a server when trying mod_rewrite for the first time:


RewriteEngine on
#
RewriteRule ^/?go-google\.html$ http://www.google.com [R=301,L]

Then if you request "go-google.html" from your site, you should get redirected to Google's site. If not, then you need to back up and find out why mod_rewrite isn't working. The most likely cause is that your host has not configured mod_rewrite to be enabled by default, so try adding this Options directive:

Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^/?go-google\.html$ http://www.google.com [R=301,L]

This Options directive is required on some servers, forbidden on others, and configured by default on many. You have to test to find out which.

With that simple rule or something similar, you can get past the obvious "mod_rewrite doesn't work at all" type problems" in a tightly-scoped test environment with few external dependencies.

Jim