![](/img/trans.png)
[英]Apache 2.4 + Codeigniter Urls working on HTTP but not on HTTPS
[英]Https redirection not working on Apache 2.4
我的 apache 配置有一些问题,我正在尝试找出问题所在。
我想出了以下不起作用的行:
出于测试目的,我尝试将所有 https 流量重定向到 Yahoo
重定向不起作用,我的 web 站点显示存储在 public_html 中的 index.html 文件
Listen 443
NameVirtualHost *:443
<VirtualHost *:443>
DocumentRoot "${SRVROOT}/htdocs/example.com/public_html"
ServerName example.com
ServerAlias example
Redirect permanent / https://www.yahoo.com/
</VirtualHost>
有人可以帮忙吗?
谢谢
将此用于重定向,还启用 mod_rewrite 使其工作:
将此添加到 .htaccess 文件的顶部:
RewriteEngine On #Don't use RewriteEngine On twice in one .htaccess file
RewriteBase /
RewriteRule ^(.*)$ https://www.yahoo.com [R=301,L]
清除浏览器的缓存以使用与 yahoo.com 不同的重定向,一旦它工作。
如果您希望网站的所有流量都重定向到同一域上的 https://,请执行以下操作,不要删除RewriteEngine On
和RewriteBase /
:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
如果您想使用 https 将所有流量重定向到一个域:
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST] !^example.com
RewriteRule ^(.*)$ https://example.com [R=301,L]
如果您想使用 https 和 www 将所有流量重定向到一个域:
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST] !^www.example.com
RewriteRule ^(.*)$ https://www.example.com [R=301,L]
RewriteEngine 开启 RewriteCond %{HTTPS} 关闭 RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.