【问题标题】:How can I make this RewriteRule working?我怎样才能使这个 RewriteRule 工作?
【发布时间】:2012-08-27 17:26:27
【问题描述】:
RewriteRule ^articles\.php\?id=([0-9]+)$ article-a$1.html [R=301,L]

我想让所有链接如articles.php?id=1211 指向article-a{ID}.html,我该如何实现?这条规则有什么问题?

【问题讨论】:

    标签: php apache mod-rewrite rewrite


    【解决方案1】:

    您无法匹配重写规则中的查询字符串,您需要匹配条件中的%{QUERY_STRING} var 并使用% 反向引用:

    RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ 
    RewriteRule ^articles\.php$ article-a%1.html [R=301,L]
    

    【讨论】:

      【解决方案2】:

      使用以下,

      RewriteRule ^articles.php?id=([0-9]+)$ article-a$1.html
      

      【讨论】:

      • 绝对不是。您无法以 RewriteRule 的模式测试查询字符串。
      猜你喜欢
      • 2012-08-21
      • 1970-01-01
      • 2018-01-21
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-26
      相关资源
      最近更新 更多