Forum Moderators: phranque

Message Too Old, No Replies

rewritecond for multilingual usage

how to use htaccess for use within multilingual websites

         

smcman

8:09 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Hi here, I'm confusing myself with .htaccess file I'm building for a french and english website.

I want to follow the [domain.com...] and [domain.com...] format, with the language code (only fr or en) first.

However I would like to provide the option of [domain.com...] format that would automatically redirect the page to the default language (english in this case).

I'm working with the following code but its really confusing me and I want to know how I can fix it. If anyone can help me or give me links ill be very grateful.

CODE:


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}!^(en¦fr)(.+)$ [NC]
RewriteRule ^.*$ /en/$1 [R]

thanks in advance,

shaun

gergoe

12:23 am on Jan 9, 2008 (gmt 0)

10+ Year Member



The solution is much simpler as you may have thought, seems you got yourself confused quite well :-)

If you only want to make sure that the url without the language code gets redirected to the English one, then you only need this:

RewriteEngine On 
RewriteBase /
RewriteRule ^news/([0-9]+)/?$ /en/$1 [R,L]

But if this code is supposed to do URL to filename mapping (so your script will be called each time someone requests such a page, then the following will do the job:

RewriteEngine On 
RewriteBase /
RewriteRule ^news/([0-9]+)/?$ en/news/$1 [NC]
RewriteRule ^(en¦fr)/news/([0-9]+)/?$ your_script?language=$1&newsid=$2 [NC,L]

jdMorgan

1:34 am on Jan 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For the redirect rule, I'd suggest:

RewriteRule [b]^(news/[/b][0-9]+)/?$ [b]http://www.example.com[/b]/en/$1 [[b]R=301[/b],L]

Jim