Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess multiple parameters rewrite rule

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 !

like image 659
ovesco Avatar asked Dec 09 '13 10:12

ovesco


2 Answers

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]
like image 70
anubhava Avatar answered Oct 18 '22 00:10

anubhava


Try something like this

RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/([a-z0-9_-]+)\.html$           index.php?param1=$1&param2=$2&param3=$3
like image 23
amarjit singh Avatar answered Oct 17 '22 23:10

amarjit singh