htaccess多个参数重写规则

sol*_*ana 4 php regex apache .htaccess mod-rewrite

我知道这个问题已经过时,但找不到任何适合我的问题.

我正在创建一个网站,我的网址如下:

www.foo.com/或www.foo.com/index.php.他们可以采取1,2或三个不同的参数,如

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
Run Code Online (Sandbox Code Playgroud)

页面参数是必需的,其他两个不是..我无法为我工作......任何帮助都会受到高度赞赏

非常感谢 !

anu*_*ava 9

最好有单独的清洁规则.将此代码放入您的DOCUMENT_ROOT/.htaccess文件中:

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]
Run Code Online (Sandbox Code Playgroud)