Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在apache上强制使用https_Apache_.htaccess_Ssl_Https_No Www - Fatal编程技术网

在apache上强制使用https

在apache上强制使用https,apache,.htaccess,ssl,https,no-www,Apache,.htaccess,Ssl,Https,No Www,我使用Apache服务器发布我的网站。问题是我想强制我的网站使用HTTPS。例如,如果有人输入URL“”,它应该重定向到“” 我使用以下规则创建了一个.htaccess文件: # To use 404.html as default 404 error page. ErrorDocument 404 /404.html # To force website use https and remove www. subdomain. RewriteEngine On RewriteCond %

我使用Apache服务器发布我的网站。问题是我想强制我的网站使用HTTPS。例如,如果有人输入URL“”,它应该重定向到“”

我使用以下规则创建了一个
.htaccess
文件:

# To use 404.html as default 404 error page.
ErrorDocument 404 /404.html


# To force website use https and remove www. subdomain.
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://alireza.co/$1 [R=301,L]
现在的问题是,每当我输入URL时,无论是使用
https
http
,还是使用
www.
或不使用它,我都会收到错误
过多重定向
Firefox中的网站没有正确重定向


我使用作为我的主机提供程序。我的网站是静态的(仅HTML/CSS)。我试了很多方法,但都没有成功。

我刚想出来。我唯一要做的就是用以下简单的规则重写我的
.htaccess
文件:

# To remove www. from URL
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.alireza\.co [NC]
RewriteRule ^(.*)$ https://alireza.co/$1 [L,R=301]
#To force HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

# To make 404.html default 404 error page
ErrorDocument 404 /404.html
删除
www.
很简单
.htaccess
规则,但是我让它重定向到$1而不是$1