.htaccess使用request_uri和query_string中的参数 [英] .htaccess use parameter from request_uri and query_string
问题描述
我尝试通过以下结构调用页面:
I try to get call a page with this structure:
/page/my-selection.html?p=1
/page/my-selection2.html?p=3
/page/my-selection3.html?p=6
其中my-selection,my-selection2,...是数据库密钥,而p是分页.我想在一个页面上重定向它,这完成了所有的魔术,但是我如何使用mod_rewrite来使用两个RewriteCond的变量?
where my-selection, my-selection2, ... is a database key and p the pagination. I want to redirect this on one single page, which does all the magic, but how i can use mod_rewrite to use the variables from both RewriteCond's?
我这样尝试过,有点不起作用:
I tried it this way, bit it doesn't work:
RewriteCond %{REQUEST_URI} page/(.*)\.html [NC]
RewriteCond %{QUERY_STRING} ^p=(.*)
RewriteRule page/(.*)\.html$ /rewrites/page.php?selection=$1&pagination=$2 [NC]
示例:
- /page/my-selection.html?p=1应该重定向到/rewrites/page.php?selection=my-selection&pagination=1
- /page/my-selection2.html?p=3应该重定向到/rewrites/page.php?selection=my-selection2&pagination=3
- /page/my-selection3.html?p=6应该重定向到
/rewrites/page.php?selection=my-selection3&pagination=6
有什么想法吗?!
推荐答案
尝试使用:
RewriteCond %{QUERY_STRING} ^p=(.*)
RewriteRule ^page/(.*)\.html$ /rewrites/page.php?selection=$1&pagination=%1 [NC,L]
RewriteRule反向引用:这些是$ N形式的反向引用(0< = N< = 9),它提供对分组部分的访问(在的圆括号),取决于要接受的RewriteRule当前的RewriteCond条件集.
RewriteCond反向引用:这些是%N形式的反向引用(1 <== N <= 9),可以访问以下内容的分组部分(再次在括号中)模式,来自当前组中最后匹配的RewriteCond条件. http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond
RewriteRule backreferences: These are backreferences of the form $N (0 <= N <= 9), which provide access to the grouped parts (in parentheses) of the pattern, from the RewriteRule which is subject to the current set of RewriteCond conditions..
RewriteCond backreferences: These are backreferences of the form %N (1 <= N <= 9), which provide access to the grouped parts (again, in parentheses) of the pattern, from the last matched RewriteCond in the current set of conditions. http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond
这篇关于.htaccess使用request_uri和query_string中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!