【问题标题】:PHP & Apache Mod rewrite: search?keywordPHP 和 Apache Mod_rewrite:搜索?关键字
【发布时间】:2010-11-08 13:49:56
【问题描述】:

这些是我通常用于干净 url 的重写规则,

RewriteRule ^([a-zA-Z0-9\-]+)/?$  index.php?pg_url=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$  index.php?pg_url=$2 [L,QSA]

他们将接受请求的网址,例如,

mysite/home
mysite/portfolio/photograhy

但是如何设置搜索的重写规则,例如,

mysite/search?photograhy
mysite/search?painting

我试过下面这个,

RewriteRule ^search?([a-zA-Z0-9\-]+)/?$ index.php?pg_url=search&keyword=$1[L,QSA]

他们的关键字搜索不会正确显示,但无论我搜索什么,我都会在下面得到这个,

echo $_REQUEST['keyword'];


h[L,QSA] // result

谢谢。

【问题讨论】:

    标签: php regex apache search mod-rewrite


    【解决方案1】:

    您需要为查询字符串使用 RewriteCond,例如:

    RewriteCond %{QUERY_STRING} ^keyword=([a-zA-Z0-9\-]+)$
    

    您需要调整查询以执行?keyword=photography 之类的操作

    这里有一些关于这个主题的阅读:http://wiki.apache.org/httpd/RewriteQueryString

    【讨论】:

      猜你喜欢
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多