.htaccess使用request

编程入门 行业动态 更新时间:2024-10-18 16:50:23
本文介绍了.htaccess使用request_uri和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条件. httpd.apache/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. httpd.apache/docs/2.2/mod/mod_rewrite.html#rewritecond

更多推荐

.htaccess使用request

本文发布于:2023-11-01 12:53:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:htaccess   request

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!