.htaccess文件未将HTTP重定向到HTTPS

问题描述 投票:0回答:1

我刚从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
.htaccess ssl redirect https
1个回答
0
投票

您可以使用此代码

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]
© www.soinside.com 2019 - 2024. All rights reserved.