htaccess多个参数重写规则 [英] 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/ 或www.foo.com/index.php. 它们可以采用1、2或3个不同的参数,例如
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=zh-CN&article=1
www.foo.com/index.php?page=Home&lang=en&article=1
我想要的是
www.foo.com/Home/
or www.foo.com/en/Home
or www.foo.com/Article/1
or www.foo.com/en/Article/1
page参数是必需的,其他两个不是必需的. 我什么都帮不了我.任何帮助将不胜感激
The page parameter is required, other two are not.. I cant have anything working for me... Any help would be greately appreciated
非常感谢!
推荐答案
最好具有单独的干净规则.将此代码放在您的DOCUMENT_ROOT/.htaccess
文件中:
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]
这篇关于htaccess多个参数重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!