Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/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
在URL中为HTTP和HTTPS追加www_Url_Mod Rewrite_Https - Fatal编程技术网

在URL中为HTTP和HTTPS追加www

在URL中为HTTP和HTTPS追加www,url,mod-rewrite,https,Url,Mod Rewrite,Https,我的网站上有些页面使用http,有些页面使用https。现在我想使用mod_rewrite将www附加到所有URL,无论它们使用http还是https 我的当前代码在.htaccess中: RewriteCond %{HTTP_HOST} ^domain.com$ [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST

我的网站上有些页面使用http,有些页面使用https。现在我想使用mod_rewrite将www附加到所有URL,无论它们使用http还是https

我的当前代码在.htaccess中:

RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index.php
RewriteCond $1 !^(index\.php|public|assets|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
请只关注前两行,因为其余的是其他重写规则,但我将其包括在内,以防它们导致我的前两行出现任何错误


现在,这会将所有页面重定向到http,但我希望使用https的页面重定向到正确的协议。我尝试了StackOverflow()上的线程解决方案,但它对我无效。

您链接的答案应该可以很好地解决问题。如果它不工作,则可能未设置HTTPS变量。这通常是因为您没有在apache服务器上执行HTTPS。也许你有一个代理,或者负载平衡器?在这种情况下,您需要确保设置HTTPS变量。类似的事情通常会起作用(该示例适用于amazon弹性负载平衡器):


您的HTTPS是通过mod_ssl还是其他方式提供的?
SetEnvIf X-Forwarded-Proto https HTTPS=1