Welcome to WebmasterWorld Guest from 3.234.214.179

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

.htaccess mod_rewrite question

     
6:01 pm on Dec 18, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 4, 2003
posts:61
votes: 0


Hi all,

Thank you for taking the time to open this message. Before reading any further please understand that I have no knowledge of .htaccess and am continuing something a former employee created. That aside, on to the question!

I have a Canadian site and an American site that are identical in all but a few pages - we'll call these pages the xfiles.

What I want to do is use .htaccess to reference my geographical list of ips and redirect the Canadian user when the xfiles are requested. At the moment I am redirecting all Canadian users that load mysite.com to mysite.ca, which is highly inefficient.

My current .htaccess looks like this:

RewriteEngine on

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteCond %{HTTP_HOST}!^www\.mysite\.ca$
RewriteRule ^(.*) [mysite.ca...] [R=301,L]

RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteRule (.*) [mysite.com...] [R=301,L]

After asking around a bit - someone gave me this as a solution:

RewriteEngine on

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteCond %{HTTP_HOST}!^www\.mysite\.com$
RewriteRule ^/ca/widgets.html$ [mysite.com...] [R=301,L]

RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteRule (.*) [mysite.com...] [R=301,L]

Unfortunately it does not work.

Also - I am wonder if this would work with .txt virtual includes.

Thank you so much!

Hayden

6:33 pm on Dec 18, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Hayden,

I'll answer the second question first:
.htaccess cannot include-virtual text files -- everything you want to do has to be contained within the .htaccess file itself. If you have server privileges, you can use RewriteMap in httpd.conf to implement lookup-table functions, but this in not available in .htaccess.

As you your other (bigger) question, I'm afraid there's not enough infomation there about exactly which files you are trying to redirect. It is impossible to propose a solution without a clear understanding of the goal. What (I think) is needed is a list of the pages which are not common between the sites (the non-xfiles, to use your term), or a statement as to which directory they are in.

Since we can't "see over your shoulder," it's not obvious what the goal is.

Jim

8:01 pm on Dec 18, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 4, 2003
posts:61
votes: 0


Jd,

Apologies for the lack of information.

Currently all the .html and .txt files reside in my root. If it is easier I can simply create a directory for the xfiles. On the test I ran (which didn't work) I ran it only on order.html and put that in a folder off the root entitled "ca". The .htaccess I gave as an example was the .htaccess on the my root htdocs folder.

Here is a list of the xfiles:

order.html
shipping.html
popup.html
asianlinks.html
index.html

I have a virtual include that is the footer to my site, and the email link on the ca points to a different address then the link on the com. It would be mighty useful if I could have it load a different .txt file using the method you specified, however I don't want to get in over my head (I'm deep enough with mod_rewrite!).

I do know that I can download and edit the conf file however.

8:30 am on Dec 19, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Hayden,

I'd recommend leaving common files in the root directory or in a /common subdirectory, and then setting up subdirectories like /ca and /wo for the files that differ based on geoip. I think that using a /common subdirectory might be advantageous, because then all of your relative filepaths start at the same 'depth'.

Included text files are requested within a single HTTP request, and are accessed by filepath and not by URL, so mod_rewrite is not invoked... I'll need to think about that some more, but one thing that comes to mind is to use conditional SSI to test the same geoip info, and select the proper include within each html page.

Have to ponder the main problem a bit more, too...

Jim

3:20 pm on Dec 22, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 4, 2003
posts:61
votes: 0


Jim - any update since your last post?

Thanks,
Hayden

3:31 pm on Dec 22, 2003 (gmt 0)

Full Member

10+ Year Member

joined:May 22, 2003
posts:312
votes: 0


Hayden,

You could set an environmental variable based on the ip address that would indicate whether it was a use or ca user and include the appropriate footer based on that.

My other suggestion, since you claim to know nothing about .htaccess, is to spend a day or so reading here:

[httpd.apache.org...]

That's how I learned how to use apache and it's quite empowering once you start to get the hang of it.

Pete

12:36 am on Dec 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Hayden,

It looks like tolachi and I may be recommending the same solution:

Use mod_rewrite to set an environment variable accoring to your geo_ip results.

Using conditional SSI, check that environment variable on each location-dependent html page, and then conditionally include the appropriate content.

Alternatively, you could use SSI to call a script which would then check that variable and generate the correct content on the fly.

Jim

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members