求一段伪静态代码

cnaaa8 2017-09-29 04:18:51
原地址 http://mytaobaoke/index.php?q=手机 (手机可能是数字,字母,汉字 ,符号等)
重定向到 index.php/index/index/q?q=手机

不能影响其他的链接,比如访问 http://mytaobaoke/index.php 还是访问的以前的路径,只有后面是 http://mytaobaoke/index.php?q=手机 时 ,才重定向到 index.php/index/index/q?q=手机

用在apache2.4上,以下是我的代码,一直不行
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index.php?q=(.*)$ index.php/index/index/q?q=$1 [QSA,PT,L]
</IfModule>
...全文
562 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_38741240 2018-01-04
  • 打赏
  • 举报
回复
RewriteEngine on RewriteCond %{QUERY_STRING} ^q=(.+)$ RewriteRule ^search\.php$ /index.php/keyWords/Keyword/q=%1? [R,L]
cnaaa8 2017-10-09
  • 打赏
  • 举报
回复
引用 1 楼 hongmei85 的回复:
RewriteCond %{QUERY_STRING} ^q=.+$ RewriteRule ^index\.php$ /index.php/index/index/q [QSA,R]
RewriteRule ^index.php?q=(.*)$ index.php/index/index/q?q=$1 [QSA,PT,L] 我这么写有什么不对吗?不想写带 RewriteCond %{QUERY_STRING} ^q=.+$ 这行 ,还有别的办法吗
cnaaa8 2017-10-09
  • 打赏
  • 举报
回复
引用 2 楼 sinat_28757329 的回复:
在正则表达式中,“?”是特殊字符,需要转义。
怎么转义呢,转义后的该如何写呢
du56du 2017-10-03
  • 打赏
  • 举报
回复
在正则表达式中,“?”是特殊字符,需要转义。
hongmei85 2017-09-30
  • 打赏
  • 举报
回复
RewriteCond %{QUERY_STRING} ^q=.+$ RewriteRule ^index\.php$ /index.php/index/index/q [QSA,R]

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧