homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

blank .htaccess

 3:29 pm on Apr 10, 2003 (gmt 0)

Hi, I have a .htaccess that references an apache module that is a list of geographical ips. It automatically redirects the user to a .ca version of the site if the user is Canadian.

RewriteEngine on

RewriteRule ^(.*)$ [url.ca...] [L]

The problem is that url.ca is just a folder called "ca" in url.com, so I get a loop. If I redirect to any other external domain it works fine.

To solve this I placed a blank .htaccess in the "ca" folder. Apache didn't seem to recognise it so I placed an .htaccess with the following:


And it worked. I came in today, and it no longer works.

Any ideas?



 4:07 pm on Apr 10, 2003 (gmt 0)


To prevent a loop, add code to stop the redirect to www.url.ca if you already are in www.url.ca:

RewriteCond %{HTTP_HOST} !^www\.url\.ca$
RewriteRule .* http://www.url.ca/ [R=301,L]

As coded, this will redirect a request for any page in a non-.ca domain to the home page in .ca if the user's IP is determined to be Canadian. The important part here is that it redirects any page to the home page. Is that what you want to do?

Another note: In order to work, you must use the 301 external redirect as shown. If this is not acceptable (because you want to hide the redirect), you'll need to implement a cookie or a session-tracking variable to keep track of each visitor's current country-domain.



 4:18 pm on Apr 10, 2003 (gmt 0)

Thanks Jim, I'll try it.

Why do I need to use the 301 redirect? Not trying to be difficult, just curious.


 4:22 pm on Apr 10, 2003 (gmt 0)

So that Apache "knows" that it's been redirected to the .ca domain, and the second RewriteCond can detect that fact.

Otherwise, that test would fail, and you're back to looping...


<added>Or is it not a different domain? - I may be misreading here.</added>


 4:51 pm on Apr 10, 2003 (gmt 0)


I've got some other things I need to get done, and I'll be off-line for awhile, so here's a "just-in-case". Assuming that you meant to say www.url.com/ca, rather than www.url.ca, you can use this.

To prevent a loop, add code to stop the redirect to www.url.com/ca if you are already in www.url.com/ca:

RewriteCond %{REQUEST_URI} !^/ca
RewriteRule ^(.*)$ /ca/$1 [L]

However, this redirects any page requested by a user with a Canadian IP to that same page in the /ca folder.

If you really want to redirect only to the /ca home page, use:

RewriteCond %{REQUEST_URI} !^/ca
RewriteRule .* /ca/ [L]

This will mean that only the /ca homepage will be accessible to Canadian IPs.



 3:11 pm on Apr 14, 2003 (gmt 0)

Thanks JD! The following worked like a charm:

RewriteCond %{HTTP_HOST}!^www\.url\.ca$
RewriteRule .* [url.ca...] [R=301,L]


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved