向站点添加了 SSL 证书。现在有必要将通过 http: 对站点的任何请求自动转换为 https:
告诉我您需要如何更改此 .htaccess 以获得所需的行为:
AddDefaultCharset UTF-8
ErrorDocument 404 /index.php?page=404
RewriteEngine On
RewriteCond %{HTTP_HOST} ^somedomain\.ru
RewriteRule ^(.*)$ http://www.somedomain.ru/$1 [R=301,L]
RewriteBase /
# RewriteRule ^index.php$ / [R=301,L]
RewriteRule ^test/(x.+/)?$ index.php?page=test [L]
RewriteRule ^test/create/((de|es)/)?$ index.php?page=create&lang=$2 [L]
RewriteRule ^test/create/(([0-9A-Fa-f]+)/)?$ index.php?page=create&token=$2 [L]
RewriteRule ^test/([^/]+)/$ index.php?page=test&act=$1 [L]
RewriteRule ^test/replay/([0-9A-Za-z]+)/$ index.php?page=test&replay=$1 [L]
只需更改行:
RewriteRule ^(.*)$ http://www.somedomain.ru/$1 [R=301,L]
在:
RewriteRule ^(.*)$ https://www.somedomain.ru/$1 [R=301,L]
并非在所有情况下都提供所需的行为。
UPD:将 .htaccess 更新为@Alex 的回答中的选项 9:
AddDefaultCharset UTF-8
ErrorDocument 404 /index.php?page=404
RewriteEngine On
# https://masterhost.ru/support/doc/apache/#http2https
RewriteCond %{HTTP:PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# https://masterhost.ru/support/doc/apache/#redirect
RewriteCond %{HTTP_HOST} ^somedomain\.ru
RewriteRule ^(.*)$ https://www.somedomain.ru/$1 [R=301,L]
# старый вариант переадресации на www.
#RewriteCond %{HTTP_HOST} ^somedomain\.ru
#RewriteRule ^(.*)$ http://www.somedomain.ru/$1 [R=301,L]
RewriteBase /
# RewriteRule ^index.php$ / [R=301,L]
RewriteRule ^test/(x.+/)?$ index.php?page=test [L]
RewriteRule ^test/create/((de|es)/)?$ index.php?page=create&lang=$2 [L]
RewriteRule ^test/create/(([0-9A-Fa-f]+)/)?$ index.php?page=create&token=$2 [L]
RewriteRule ^test/([^/]+)/$ index.php?page=test&act=$1 [L]
RewriteRule ^test/replay/([0-9A-Za-z]+)/$ index.php?page=test&replay=$1 [L]
...有效。
这一切都取决于托管商的设置,所以我建议首先查看托管商的常见问题解答,这将为您节省很多问题并节省大量时间。
我将在下面列出几个选项。建议在指令之后立即编写
选项1
选项 2
选项 3
选项 4
选项 5
选项 6
选项 7
选项 8
选项 9