【问题标题】:htaccess manipulate query stringhtaccess 操作查询字符串
【发布时间】:2018-09-26 05:51:14
【问题描述】:

我正在尝试编写 htaccess 规则来转换以下形式的 URL:

http://example.com/PageViewer.aspx?id=348

到:

http://example.com/?page_id=15348

数字 15 是常量,后面是原始 URL 中 id 的值。

我尝试了以下规则:

RewriteCond %{QUERY_STRING} ^(.*)\id=(.*)$
RewriteRule ^(.*)PageViewer\.aspx$ $1?%1page_id=15%2 

但是,我得到的结果是这样的:

http://example.com/page_id=15348/?id=348

为什么缺少规则中使用的问号?为什么查询字符串显示在结果 URL 的末尾?我对htaccess重写规则不太了解...

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    使用[NE]标志解决

    RewriteCond %{QUERY_STRING} ^(.*)\id=(.*)$
    RewriteRule ^(.*)PageViewer\.aspx$ $1?%1page_id=15%2 [NE]
    

    【讨论】:

      猜你喜欢
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-06
      • 2010-11-16
      • 1970-01-01
      相关资源
      最近更新 更多