php - 如何通过允许 mod_rewrite 作为查询字符串和页码进行 .htaccess 搜索?
问题描述
我的原始文件是一个名为search.php
.
通常,搜索功能将是:
mydomain.com/search.php cid=&type=search&q=keyword+text&page=2
但是,是否可以将其重写为mydomain.com/all.html?q=keyword+text&page=[1-anypage]
?
我试图将此代码放入.htaccess:
RewriteRule ^all.html?q=([^.*]+)&p=([0-9]+)$ search.php?cid=&type=search&q=$1&p=$2 [L]
但出了点问题。
请帮我找到解决方案。谢谢。
解决方案
是的,它可能,但您无法匹配 RewriteRule 模式中的查询字符串,您将需要使用RewriteCond
指令来检查%{QUERY_STRING}
类似以下内容
RewriteEngine On
RewriteCond %{QUERY_STRING} ^q=([^&]+)&page=(.+)$ [NC]
RewriteRule ^all\.html$ /search.php?cid=&type=search&q=%1page=%2 [L]
推荐阅读
- java - 通过阻止公共访问来保护部署到同一 WebLogic 服务器的 2 个应用程序
- python - 如何让汤解析不同风格的亚马逊网页
- angular - 嵌套表行以角度 5 排序
- spring - application.yml 中的 Spring Boot 日志设置
- ruby-on-rails-5 - 将变量传递给方法 info_for_paper_trail
- ssl - 安装 kafka-connect-spooldir 不起作用
- azure - Microsoft Identity Platform V2 不适用于个人帐户
- react-native - 在滑块更改时动态更新地图标记 - React Native
- r - 如何在闪亮的应用程序中浏览和上传图像?
- python - 如何在数据框中逐行查找连续减少(或增加)的最长运行