简体   繁体   English

Https 重定向不适用于 Apache 2.4

[英]Https redirection not working on Apache 2.4

I had some issues with my apache configuration and I'm trying to isolate the problem.我的 apache 配置有一些问题,我正在尝试找出问题所在。

I came up with the following lines which are not working:我想出了以下不起作用的行:

For testing purposes, I'm trying to redirect all https traffic to Yahoo出于测试目的,我尝试将所有 https 流量重定向到 Yahoo

The redirection is not working and my web site is showing the index.html file stored in public_html重定向不起作用,我的 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> 

Can anyone help please?有人可以帮忙吗?

Thanks谢谢

Use this for the redirect, also enable mod_rewrite for this to work:将此用于重定向,还启用 mod_rewrite 使其工作:

Add this to the top of your .htaccess file:将此添加到 .htaccess 文件的顶部:

RewriteEngine On #Don't use RewriteEngine On twice in one .htaccess file
RewriteBase /
RewriteRule ^(.*)$ https://www.yahoo.com [R=301,L]

Clear your browser's cache to have a different redirect than yahoo.com, once it works.清除浏览器的缓存以使用与 yahoo.com 不同的重定向,一旦它工作。

Just in case以防万一

If you want all traffic of your website to redirect to https:// on the same domain, do the following, don't remove RewriteEngine On and RewriteBase / :如果您希望网站的所有流量都重定向到同一域上的 https://,请执行以下操作,不要删除RewriteEngine OnRewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

If you want to redirect all traffic to one domain with https:如果您想使用 https 将所有流量重定向到一个域:

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST] !^example.com
RewriteRule ^(.*)$ https://example.com [R=301,L]

If you want to redirect all traffic to one domain with https and www:如果您想使用 https 和 www 将所有流量重定向到一个域:

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST] !^www.example.com
RewriteRule ^(.*)$ https://www.example.com [R=301,L]

RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} RewriteEngine 开启 RewriteCond %{HTTPS} 关闭 RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM