Forum Moderators: phranque

Message Too Old, No Replies

Htaccess rule for homepage only

         

XHelix

6:06 pm on Nov 4, 2011 (gmt 0)

10+ Year Member



Hi. I have installed this module: [maxmind.com...]

It is working ok.
But i want to redirect the people who only visits homepage.
Forexample: Anyone from Italy who visits domain.com should be redirected to domain.com/it
But if they visit domain.com/thread.html, then they should not be redirected to anywhere.

The current default htaccess code that i use is this.

GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

# Redirect one country
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IT$
RewriteRule ^(.*)$ http://www.italy.com$1 [L]


But it redirects visitors from Italy to another domain even if they are visiting domain.com/thread.html

Can anyone help me with the correct htaccess code ?
Sorry for poor english.

g1smd

7:20 pm on Nov 4, 2011 (gmt 0)

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



^(.*)$ is "every page".

^$ or !. is root only.

You have a 302 redirect here. Add [R=301,L] if you want a 301 redirect.

XHelix

7:58 pm on Nov 4, 2011 (gmt 0)

10+ Year Member



That is it. Solved.
Thanks.

Can i ask 2 more questions if possible?
1. is it possible to set a rule inside the htaccess, so it will redirect after some seconds ? may be after 3 seconds.

2. And is it possible that htaccess should redirect 1 time in each session. (i dont know how to explain, Just like, it will redirect once when i enter the site, but it will not redirect any more till i exit the browser and reenter the site again .)

Regards.

g1smd

8:30 pm on Nov 4, 2011 (gmt 0)

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



1. No. A 301 redirect is an immediate redirect in the server headers.

2. You'll need cookies.

XHelix

8:42 pm on Nov 4, 2011 (gmt 0)

10+ Year Member



2. You'll need cookies.


So a standalone htaccess rule is not enough for this, and I need some php script for this. Am i right ?

Highest Regards.

lucy24

9:43 pm on Nov 4, 2011 (gmt 0)

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



1. is it possible to set a rule inside the htaccess, so it will redirect after some seconds ? may be after 3 seconds.

That's an html redirect, not an htaccess redirect. Sometimes useful, sometimes annoying. Make the decision based on your site's specific circumstances.

XHelix

2:46 pm on Nov 5, 2011 (gmt 0)

10+ Year Member



Thanks.