小编Vir*_*dia的帖子

使用 .htaccess 使用多个参数重写 URL

我有四种不同类型的重写,我试图在每个重写中使用多个参数。

首先是没有修改的网址:

http://www.example.com/index.php?p=/category/page-slug&pn=2/
http://www.example.com/index.php?p=/category/&f=feed/rss (feed, feed/, feed/rss, feed/atom are the only possible values for the f parameter)
http://www.example.com/index.php?p=tag&t=tag-one+tag-two+-tag-three&pn=2/
http://www.example.com/index.php?p=search&q=search+query+goes+here&pn=2/
Run Code Online (Sandbox Code Playgroud)

接下来,我希望能够在浏览器中输入:

http://www.example.com/category/page-slug/2/
http://www.example.com/category/feed/rss 
http://www.example.com/tags/tag-one+tag-two+-tag-three/2/
http://www.example.com/search/search+query+goes+here/2/
Run Code Online (Sandbox Code Playgroud)

最后,我尝试过的,以及无数的变化:

RewriteRule ^([a-zA-Z0-9-/+]+)([0-9]+)$ index.php?p=/$1&pn=$2/ [L]
RewriteRule ^([a-zA-Z0-9-/+]+)([a-zA-Z/]+)$ index.php?p=/$1&f=$2/ [L]
RewriteRule ^([a-zA-Z0-9-/+]+)([a-zA-Z/]+)([0-9]+)$ index.php?p=/$1&t=$2&pn=$3/ [L]
RewriteRule ^([a-zA-Z0-9-/+]+)([a-zA-Z/]+)([0-9]+)$ index.php?p=/$1&q=$2&pn=$3/ [L]
Run Code Online (Sandbox Code Playgroud)

我可以使用以下方法很好地处理 p 参数:

RewriteRule ^([a-zA-Z0-9-/+]+)$ index.php?p=/$1 [L]
Run Code Online (Sandbox Code Playgroud)

然而,其他一切都完全脱离了我。我觉得我已经很接近了,但这令人非常沮丧,因为我不知道有什么方法可以缩小问题的范围。它要么有效,要么无效。提前致谢。

rewrite .htaccess

6
推荐指数
1
解决办法
4万
查看次数

标签 统计

.htaccess ×1

rewrite ×1