簡體   English   中英

Https 重定向不適用於 Apache 2.4

[英]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 OnRewriteBase /

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM