【问题标题】:All pages under ssl except index.htmlssl 下的所有页面,除了 index.html
【发布时间】:2018-12-24 09:40:44
【问题描述】:

我使用.htaccess 将页面重定向到 HTTP 而不是 HTTPS。

代码是:

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

现在,我希望索引以外的所有页面都重定向到 HTTPS。 除了index.html之外的所有。

我如何使用.htaccess 做到这一点?

【问题讨论】:

  • 请求主页时,URL是否总是包含index.html,或者example.com/是可能的URL?

标签: .htaccess mod-rewrite


【解决方案1】:

试试这样的:

# Redirect all pages, except homepage to HTTPS
RewriteCond %{HTTPS} off
RewriteRule !^(index\.html)?$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

# Redirect homepage to HTTP
RewriteCond %{HTTPS} on
RewriteRule ^(index\.html)?$ http://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

使用 302(临时)重定向进行测试以避免缓存问题。

您需要在测试前清除浏览器缓存。

【讨论】:

    猜你喜欢
    • 2022-11-02
    • 2010-10-18
    • 2015-08-20
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 2021-06-05
    • 2016-11-08
    • 1970-01-01
    相关资源
    最近更新 更多