【问题标题】:redirection http to https with exceptions将 http 重定向到 https,但有例外
【发布时间】:2017-11-15 14:11:36
【问题描述】:

我有一个网站(比如说 website.com)并使用 .htaccess 并包含以下内容:

ErrorDocument 403 /index.php
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

我需要将 http 重定向到 https。为此,我在我的虚拟主机设置中添加了这一行:

Redirect permanent / https://website.com/

因此,它将所有流量重定向到 https

我的问题是我需要为我的重定向添加例外 例如。此路由http://website.com/folder/test/* 之后的所有流量都应路由到 HTTP

请帮忙 谢谢

【问题讨论】:

标签: php apache .htaccess ssl redirect


【解决方案1】:

RewriteCond 在这种情况下会有所帮助

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


# force http:// for selected URLs
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /subfolder/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

【讨论】:

    猜你喜欢
    • 2015-03-19
    • 2013-04-25
    • 1970-01-01
    • 2012-04-02
    • 2013-04-10
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多