Apache Can';t重定向到https(htaccess)
我试图配置我的htaccess文件,该文件将使用以下语句行从http重定向到https。但它不能 注意:我不希望www在网站URL之前 我的代码可能有什么错误。任何人都可以推荐Apache Can';t重定向到https(htaccess),apache,.htaccess,http,redirect,https,Apache,.htaccess,Http,Redirect,Https,我试图配置我的htaccess文件,该文件将使用以下语句行从http重定向到https。但它不能 注意:我不希望www在网站URL之前 我的代码可能有什么错误。任何人都可以推荐 RewriteEngine on RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,L] 请尝试以下操作: 重新编写引擎打开
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,L]
请尝试以下操作:
重新编写引擎打开
重写cond%{HTTPS}=在…上
重写规则^.*$https://%{SERVER_NAME}%{REQUEST_URI}[R,L]
请尝试以下操作:
重新编写引擎打开
重写cond%{HTTPS}=在…上
重写规则^.*$https://%{SERVER_NAME}%{REQUEST_URI}[R,L]
问题似乎是这一行:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
此行使此规则仅适用于以www
开头的域
您需要使用以下选项使启动www
成为可选:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
问题似乎是这一行:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
此行使此规则仅适用于以www
开头的域
您需要使用以下选项使启动www
成为可选:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
作为另一种解决方案,如果您只有一个域名
(www.example.com
,则可以使用更具可读性的:
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]
作为另一种解决方案,如果您只有一个域名
(www.example.com
,则可以使用更具可读性的:
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]