htaccess multiple parameters rewrite rule

对着背影说爱祢 提交于 2019-12-29 07:10:06

问题


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 !


回答1:


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]



回答2:


Try something like this

RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/([a-z0-9_-]+)\.html$           index.php?param1=$1&param2=$2&param3=$3


来源:https://stackoverflow.com/questions/20468460/htaccess-multiple-parameters-rewrite-rule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!