Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/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
如何强制https和www.in.htaccess?_.htaccess_Mod Rewrite_Https - Fatal编程技术网

如何强制https和www.in.htaccess?

如何强制https和www.in.htaccess?,.htaccess,mod-rewrite,https,.htaccess,Mod Rewrite,Https,comI在.htaccess中尝试了以下代码,以强制使用https和www。因为我总是想要一个像这样的URL 如果我在浏览器中键入以下内容,则效果良好: www.domain.com domain.com http://www.domain.com http://domain.com 但如果我键入以下行,则不会发生转发: https://domain.com 如何解决此问题?所有重定向都需要以下两条规则: RewriteEngine On RewriteCond %{HTTPS} off

comI在.htaccess中尝试了以下代码,以强制使用https和www。因为我总是想要一个像这样的URL

如果我在浏览器中键入以下内容,则效果良好:

www.domain.com
domain.com
http://www.domain.com
http://domain.com
但如果我键入以下行,则不会发生转发:

https://domain.com

如何解决此问题?

所有重定向都需要以下两条规则:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]

很抱歉,由于覆盖了以.biz结尾的我的原始域而出错。对于本例,它仅是domain.com-请参阅已编辑的问题。这是相同的问题。一切正常,但如果我输入https://而不输入www,结果是https://domain.comcheck 更新规则并确保在新浏览器中进行测试我使用新代码、新浏览器和清除的缓存进行了尝试。还是一样的问题。这些规则是正确的,正如你所看到的https://domain.com 将被重定向到https://www.domain.com 在上面的第二条规则中。您有一些其他规则或冲突代码。您可以打开firebug并输入https://domain.com 在浏览器中查看“网络”选项卡中的重定向。
RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]