.htaccess文件未将HTTP重定向到HTTPS
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.htaccess文件未将HTTP重定向到HTTPS相关的知识,希望对你有一定的参考价值。
我刚从GoDaddy购买了UCC / SAN SSL证书,现在我正试图让我的网站(mannyrothman.com)自动从HTTP重定向到HTTPS。
这是我的“.htaccess”文件的内容:
## Go Daddy servers need the Options -MultiViews code below
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Hide .html extension
## External Redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+)index.html [NC]
RewriteCond %{REQUEST_URI} !^/.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteRule ^ %1 [R,NC]
## ## Internal Redirect
RewriteCond %{REQUEST_FILENAME}index.html -f
RewriteCond %{REQUEST_URI} !^/.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteRule ^ %{REQUEST_URI}index.html
# Begin Muse Generated redirects
# End Muse Generated redirects
答案
您可以使用此代码
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
要么
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
如果你想从https://ww.stackoverflow.com/重定向到https://stackoverflow.com/,也可以使用它
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.rawertest.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
以上是关于.htaccess文件未将HTTP重定向到HTTPS的主要内容,如果未能解决你的问题,请参考以下文章
在 Yii2 .htaccess 中将 http 重定向到 https
如何使用 .htaccess 正确地将 HTTP 301 重定向到 HTTPS?