htaccess multiple parameters rewrite rule

2020-02-06 03:26发布

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 !

2条回答
Lonely孤独者°
2楼-- · 2020-02-06 03:49

Try something like this

RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/([a-z0-9_-]+)\.html$           index.php?param1=$1&param2=$2&param3=$3
查看更多
Rolldiameter
3楼-- · 2020-02-06 04:13

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]
查看更多
登录 后发表回答