Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/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
Apache 使用带https的mod_重写_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Apache 使用带https的mod_重写

Apache 使用带https的mod_重写,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,我需要将所有请求从sub.domain.com重定向到sub.domain.com/www 我在.htaccess中使用了以下代码: RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ RewriteRule ^$ www/ [L] 当我通过http进入站点时,这种方式很好,但当我通过https(例如https://sub.domain.com,它不断将我重定向到http。如何将https请求重定向到http

我需要将所有请求从
sub.domain.com
重定向到
sub.domain.com/www

我在.htaccess中使用了以下代码:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$
RewriteRule ^$ www/ [L]

当我通过http进入站点时,这种方式很好,但当我通过https(例如
https://sub.domain.com
,它不断将我重定向到http。如何将https请求重定向到https?(我尝试了100种解决方案,但没有任何效果)。

假设您只需要https。。您首先要强制http请求使用https:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
然后继续进行常规重定向

RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$
RewriteRule ^$ www/ [L]

问题解决:我没有提到在子域上运行的应用程序使用Nette框架,因为我认为它不相关。但显然Nette会覆盖mod_rewrite设置,因此必须在Nette本身中配置https的使用。

我尝试了这个方法,但当我这么做时,出于某种原因,我得到了一个重定向循环。