【问题标题】:Regular Expression For URL QueryURL查询的正则表达式
【发布时间】:2011-03-15 14:51:39
【问题描述】:

我一直在我的 htaccess 文件中使用 mod_rewrite 来重写我的 url,但在进行分页时遇到了问题。

这是我页面的网址: http://domain.com/concerts/features/folk-roots?page=2

htaccess 文件:

RewriteRule ^features/([^/]*)?page=([0-9]*)$ featureCat.php?cat=$1&page=$2 [NC,L]

没有页面查询也能正常工作,但是如果我想改变页面,我不知道如何编写正则表达式来抓取页面#。

任何想法都将不胜感激!

【问题讨论】:

    标签: .htaccess mod-rewrite friendly-url


    【解决方案1】:

    您需要在 RewriteRule 之前使用 RewriteCond 来访问查询字符串:

    RewriteCond %{QUERY_STRING} ^page=([0-9]*)$
    RewriteRule ^features/([^/]*)$ featureCat.php?cat=$1&page=%1 [NC,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      • 2015-03-12
      • 2011-12-19
      • 2022-06-16
      相关资源
      最近更新 更多