本文介绍了.htaccess RewriteRule用于带有分页的搜索页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的搜索结果页面写一个带有分页的重写规则,该规则必须满足以下条件:

I want to write a rewrite rule for my search results page with pagination, which must satisfy the following:

显示网址​​1:

/search?q=SEARCH-QUERY

实际网址1:

/search.php?q=SEARCH-QUERY

显示网址​​2:

/search?q=QUERY&p=N

实际网址2:

/search.php?q=QUERY&p=N

其中 QUERY 是变量字符串(用户输入), N 是整数(页码).

where QUERY is a variable string (user input) and N is an integer (page number).

我满足以下条件1,但我无法对其进行修改以也满足条件2.

I have the following which satisfies condition 1 above, but I couldn't manage to modify it to also satisfy condition 2.

RewriteCond %{THE_REQUEST} \s/(search)\?q=[^\s]*\s [NC]
RewriteRule ^ %1.php [L,QSA]

推荐答案

使用显示的示例,请您尝试一次.在测试URL之前,请确保清除浏览器缓存.

With your shown samples, could you please try following once.Please make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(search)\?(?:q=[^\s]*)\s [NC]
RewriteRule ^ %1.php [L,QSA]
RewriteCond %{THE_REQUEST} \s/(search)\?(?:q=[^\s]*)&(?:p=[0-9]+)\s [NC]
RewriteRule ^ %1.php [L,QSA]

这篇关于.htaccess RewriteRule用于带有分页的搜索页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 09:17