Pink Code
Pink Code

Reputation: 1834

multiple rewriterole url using htaccess

I have two language for my website. (en/fr). en is default language and i show with this url :

mydomain.com/
mydomain.com/news.php?id=XX

For second language i have this url :

mydomain.com/index.php?lang=fr

now i rewrite url using .htaccess like this :

RewriteEngine On
RewriteBase /
RewriteRule ^(fr)(/)?$  index.php?lang=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((fr)/)news/([0-9]+)/([A-Za-z0-9-]+)/?.html$ news.php?id=$1 [L]

now in output :

mydomain.com  <-- WORKED defualt
mydomain.com/fr/  <-- WORKED defualt 
mydomain.com/fr/news/id/title.html  <-- WORKED show news in fr language
mydomain.com/news/id/title.html   <-- for default language NOT WORKED

For default language (mydomain.com/news/id/title.html) not work. How do can i fix this problem ?

NOTE: for default language i don't need to add /en/ to url.

Upvotes: 2

Views: 56

Answers (1)

Jon Lin
Jon Lin

Reputation: 143856

Try:

RewriteEngine On
RewriteBase /

RewriteRule ^(fr)(/)?$  index.php?lang=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((fr)/)news/([0-9]+)/([A-Za-z0-9-]+)/?.html$ news.php?id=$2&lang=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news/([0-9]+)/([A-Za-z0-9-]+)/?.html$ news.php?id=$1 [L]

You're missing the rule that rewrites without the /fr/ in front.

Upvotes: 1

Related Questions