【问题标题】:.htaccess to redirect all URL to SSL excpet the one with "s" QueryString.htaccess 将所有 URL 重定向到 SSL,除了带有“s”QueryString 的 URL
【发布时间】:2016-07-29 09:01:25
【问题描述】:

我有一个 WordPress 支持的网站,我正在使用以下 .htaccess 代码将所有 URL 从 HTTP 重定向到 HTTPS

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

嗯,它工作正常!但现在我只需要使用 QueryString 's' 将一页重定向到非 SSL (HTTP) 页面。 URL的结构是-

https://www.example.com/articles/?s={random_texts} (当前)

我希望它重定向到 -

http://www.example.com/articles/?s={random_texts} (正在寻找)

【问题讨论】:

    标签: wordpress .htaccess redirect


    【解决方案1】:

    试试:

    RewriteEngine On
    RewriteCond %{THE_REQUEST} !/articles/\?s=.+ [NC]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    ##redirect /articles/\?s=.+ from https to http##
    RewriteCond %{THE_REQUEST} /articles/\?s=.+ [NC]
    RewriteCond %{HTTPS} on
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    在测试之前清除浏览器的缓存。

    【讨论】:

    • 你要去哪个网址?
    • 谢谢@anubhava 先生!
    【解决方案2】:

    感谢starkeen 稍作修改后,我发现了问题所在。这是解决查询的代码-

    RewriteEngine On
    RewriteCond %{THE_REQUEST} !/articles/ [NC]
    RewriteCond %{QUERY_STRING} !s [NC]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteCond %{THE_REQUEST} /articles/ [NC]
    RewriteCond %{QUERY_STRING} s [NC]
    RewriteCond %{HTTPS} on
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多