htaccess multiple parameters rewrite rule

.htaccess, apache, mod-rewrite, php, regex

Solution

Better to have separate clean rules. Put this code in your `DOCUMENT_ROOT/.htaccess` file:

RewriteEngine On

RewriteRule ^index\.php$ - [L]

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

RewriteRule ^([a-z]{2})/([^/]+)/?$ /index.php?page=$2&lang=$1 [L,QSA]

RewriteRule ^([a-z]{2})/([^/]+)/([0-9]+)/?$ /index.php?page=$2&lang=$1&article=$3 [L,QSA]

RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&article=$2 [L,QSA]

Problem

I know this problem is over asked, but couldnt find anything fitting with my problem. I'm currently creating a website, and my url are like : www.foo.com/ or www.foo.com/index.php. They can take 1, 2 ,or three different parameters like www.foo.com/index.php?page=Home&lang=en&article=1 What i'd like is an url like ``` www.foo.com/Home/ or www.foo.com/en/Home or www.foo.com/Article/1 or www.foo.com/en/Article/1 ``` The page parameter is required, other two are not.. I cant have anything working for me... Any help would be greately appreciated Thanks a lot !

Original source