【问题标题】:.htaccess 301 redirect including query string, but not file extension.htaccess 301 重定向包括查询字符串,但不包括文件扩展名
【发布时间】:2018-07-03 23:17:58
【问题描述】:

我正在尝试创建一个重定向,它将原始 url 的查询字符串附加到新的 url。

旧网址如下所示:http://example.com/getzip.php?zip=12345 新网址如下所示:http://example.com/zipsearch?zip=12345

RewriteCond %{REQUEST_URI} ^/getzip(.*)$
RewriteRule ^(.*) http://example.com/zipsearch%1 [R=302,NC]

上面的代码几乎可以工作,但它也将 .php 扩展名附加到新的 url,这破坏了它。有没有办法在没有扩展名的情况下获取查询字符串?

【问题讨论】:

    标签: .htaccess url-redirection


    【解决方案1】:

    对于您的重定向,您需要一个简单的规则,如下所示:

    RewriteEngine On
    
    RewriteRule ^getzip\.php$ /zipsearch [L,R=301,NC]
    

    查询字符串将自动转移到新的目标 URL。确保在新浏览器中测试以避免旧缓存。

    【讨论】:

      猜你喜欢
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      相关资源
      最近更新 更多