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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
.htaccess 将整个站点重定向到https_.htaccess - Fatal编程技术网

.htaccess 将整个站点重定向到https

.htaccess 将整个站点重定向到https,.htaccess,.htaccess,我想重定向我的整个网站,包括所有子域到https 这样行吗 RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] 是的,那会有用的 重要的是要确保规则在您可能拥有的任何路由规则之前是,并且没有其他规则重定向到http://而您的代码可以正常工作,但我建议使用%{http\u HOST}而不是%{SERVER\u NAME}。请理解两个变量之

我想重定向我的整个网站,包括所有子域到https

这样行吗

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
是的,那会有用的


重要的是要确保规则在您可能拥有的任何路由规则之前是,并且没有其他规则重定向到
http://

而您的代码可以正常工作,但我建议使用
%{http\u HOST}
而不是
%{SERVER\u NAME}
。请理解两个变量之间的差异
%{SERVER_NAME}
是在Apache配置中配置的服务器名称,但稍后的名称是在HTTP请求中实时接收的域名。因此,不要使用代码,而是使用以下内容:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} Off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
要排除特定子域的上述规则,请使用以下代码:

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

你自己测试吗?谢谢!如果我想重定向整个网站,除了一个子域名,我会怎么做呢?