【问题标题】:force redirect to https via htaccess file通过 htaccess 文件强制重定向到 https
【发布时间】:2017-10-12 19:23:44
【问题描述】:

我想强制将任何对我网站的访问重定向到 https。
我的 htaccess 规则如下:

# rewrite address
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mytestsite\.eu$ [NC]
RewriteRule ^(.*)$ https://www.mytestsite.eu/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ https://www.mytestsite.eu/$1 [R=301,L]

#RewriteCond %{HTTP_HOST} ^(.+)\.mytestsite\.eu$   [NC] 
#RewriteCond %{HTTP_HOST} !^www\. 
#RewriteRule ^ https://www.mytestsite.eu/  [L,R] 

我怎样才能做到这一点?

【问题讨论】:

    标签: .htaccess https url-redirection http-redirect


    【解决方案1】:

    像这样重写前三行:

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

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 2020-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多