Current time: 04-19-2014, 02:53 AM Hello There, Guest! (LoginRegister)

Post Reply 
mod_rewrite challenge ...
03-18-2012, 03:52 PM
Post: #1
mod_rewrite challenge ...
... for me, anyway.

I have a PHP/MySQL website that displays content in either English or French. PHP codes works correctly to populate the website with the correct content -- when Apache receives a properly structured Request URI and query string. That's where I'm stuck. I'm using mod_rewrite to make friendly URLs.

For example, I can successfully rewrite ...

http://www.mysite.com/6-customer-stories/

to

http://www.mysite.com/page.php?menu=6

where 6 is the unique ID of a record in my webcontent database.

It becomes complicated for me when I try to account for the fact that records 1 to 21 are English content, and records 22 to 43 are French content.

mysite.com and mysite.fr serve us the same content (mysite.fr is an alias of mysite.com).

If the user does not arrive via one of my friendly URLs, but rather at site root, I need http://www.mysite.com (index.php) to serve up the home page in English, i.e. http://www.mysite.com/page.php?menu=1 and for http://www.mysite.fr (index.php) to serve up the home page is French, i.e. http://www.mysite.fr/page.php?menu=22.

Also, if the user is navigating around the .com site and decides to switch to French, he clicks the FR language switch link to, say, http://www.mysite.fr/27-temoignages-clients/

So the .htaccess file must detect that, although the %{HTTP_HOST} is http://www.mysite.com, the ID of the content being requested falls within the French range, so the RewriteRule should redirect to http://www.mysite.fr/27-temoignages-clients/

In summary, my rewrite conditions and rules need to:

* If %{HTTP_HOST} is http://www.mysite.com and the request is for index.php, rewrite to http://www.mysite.com/page.php?menu=1

* If %{HTTP_HOST} is http://www.mysite.fr and the request is for index.php, rewrite to http://www.mysite.fr/page.php?menu=22

* If %{HTTP_HOST} is http://www.mysite.com and the request starts with ID within range 1 to 22, rewrite to http://www.mysite.com/page.php?menu=[ID]

* If %{HTTP_HOST} is http://www.mysite.com and the request starts with ID within range 22 to 41, rewrite to http://www.mysite.fr/page.php?menu=[ID]

* If %{HTTP_HOST} is http://www.mysite.fr and the request starts with ID within range 22 to 41, rewrite to http://www.mysite.fr/page.php?menu=[ID]

* If %{HTTP_HOST} is http://www.mysite.fr and the request starts with ID within range 1 to 22, rewrite to http://www.mysite.com/page.php?menu=[ID]

I'm looking for a solution that is scalable because I'll likely be adding other languages. And I'm really hoping to avoid a complete site recode and database restructuring to implement this language display and switching a different way.

Any help would be greatly appreciated.

Thansk.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
mod_rewrite challenge ... - farrobo - 03-18-2012 03:52 PM
RE: mod_rewrite challenge ... - bobocat - 03-18-2012, 05:03 PM
RE: mod_rewrite challenge ... - farrobo - 03-19-2012, 12:45 PM
RE: mod_rewrite challenge ... - Andrew F - 03-19-2012, 03:03 PM
RE: mod_rewrite challenge ... - bobocat - 03-19-2012, 05:19 PM
RE: mod_rewrite challenge ... - Andrew F - 03-19-2012, 07:21 PM
RE: mod_rewrite challenge ... - bobocat - 03-19-2012, 07:28 PM
RE: mod_rewrite challenge ... - farrobo - 04-23-2012, 01:28 PM

Forum Jump: