問題描述
我知道這個問題已經問過了,但找不到適合我的問題的任何內容.
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 或三個不同的參數,例如
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
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 多參數重寫規則的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!