Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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_Https - Fatal编程技术网

.htaccess规则,用于将所有内容重定向到https://那个东西

.htaccess规则,用于将所有内容重定向到https://那个东西,.htaccess,https,.htaccess,Https,将用户的每个请求重定向到我的服务器上的任何页面到https://that 第页 例如,mydomain.com或http://mydomain.com将转到https://mydomain.com 另外,mydomain.com/projects/1.html将转到https://my domain.com/projects/1.html 无论请求的深度有多深,来自浏览器的所有请求都是https://that 位置。 我该怎么做 RewriteEngine on RewriteRule (.*)

将用户的每个请求重定向到我的服务器上的任何页面到
https://that 第页

例如,
mydomain.com
http://mydomain.com
将转到
https://mydomain.com

另外,
mydomain.com/projects/1.html
将转到
https://my domain.com/projects/1.html

无论请求的深度有多深,来自浏览器的所有请求都是
https://that 位置。

我该怎么做

RewriteEngine on
RewriteRule (.*) https://mydomain.tld$1

确保vhost位于不同的文件夹中,因此它不会明显递归。

如果使用Apache,则需要使用SSLRequireSSL指令来使用mod_ssl。 然后需要使用mod_rewrite进行重定向

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

这个答案和另一个答案有什么区别?我是否必须使用SSLRequireSSL指令来使用mod_ssl?所有ssl指令只对ssl站点本身起作用。您试图实现的只是一个HTTP主机,它将所有调用重定向到另一个vhost。另一个答案更通用,允许您在同一vhost中拥有htaccess。啊,好的。
.tld$1
是什么意思?我怎样才能确保vhost位于不同的文件夹中,这样它就不会递归运行呢?在大多数基于控制面板的托管服务器上,它们都位于不同的documentroot中,否则就要确保80和443侦听器位于不同的documentroot中。或者使用另一个答案中的RewriteCond语句来防止递归。.tld$1部分是正则表达式的替换部分,用于确保重定向后子路径保持不变。啊,我明白了。谢谢你的帮助。最后一个问题。我应该用什么替换mydomain,整个域还是只替换.com的一部分?那么它是
mydomain.tld$1
还是
mydomain.com.tld$1