【问题标题】:unwanted loop in .htaccess.htaccess 中不需要的循环
【发布时间】:2014-02-20 00:48:40
【问题描述】:

我想使用 mod_rewrite 将 http 中的所有 Url 重定向到 https,除了单个目录。

换句话说:

  1. 任何对http内容的请求都会被重定向到https中的内容
  2. 对博客目录(以 /blog/ 开头的 URI)中的内容的任何请求都将被重定向到其对应的 http。

我已经实现了以下.htaccess:

RewriteEngine On

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/blog/
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

每当我调用一个以 /blog/ 开头的请求 URI 的页面时,我都会得到一个重定向循环。我真的不明白为什么。我做错了什么?

【问题讨论】:

  • 您做错了什么是试图保护您网站的一部分。让整个事情都只用 https 并完成。
  • 整个网站都在 https 中,除了我需要使用非 https 友好的 pinterest 插件的少数页面。
  • 所以修复插件。不,我不是在开玩笑。
  • 这是官方的 Pinterest 板小部件。希望它对 SLL 友好。不幸的是,事实并非如此,我不得不忍受它。

标签: apache mod-rewrite http-redirect


【解决方案1】:

试试这个。

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

【讨论】:

    猜你喜欢
    • 2015-10-11
    • 1970-01-01
    • 2019-01-22
    • 2017-07-15
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 2019-10-06
    • 2023-03-17
    相关资源
    最近更新 更多