簡體   English   中英

如何在不更改 url 的情況下將 404page 重定向到 https 中的主頁

[英]How Redirect 404page to homepage in https without changing url

我希望在不更改 URL 的情況下將不存在頁面重定向到主頁。

我在.htaccess文件中使用以下代碼。

ErrorDocument 404 /index.php

.htaccess 適用於 http(它不會更改 URL),但使用 https 會更改當前的 Z572D14E421E5E027B。

如果您想在不更改 URL 的情況下包含index.php ,您可以在.htaccess中使用以下代碼:

ErrorDocument 404 /index.php

此代碼對 http 和 https 有效。

如果要將 http 請求重定向到 https ,可以在.htaccess中添加以下代碼:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]

重定向錯誤消息:站點將重定向到主頁,而不是提示 404 Not Found 錯誤頁面:

    Redirect 404 Error pages to the home page
    ErrorDocument 404 http://example.com/

將不存在的頁面重定向到 index.php

    Options +SymLinksIfOwnerMatch 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L] 

您也可以手動將下面的 html 代碼插入 404.php 頁面。

     <head>
     <meta http-equiv = "refresh" content = "2; url = https://www.URL.com/404.php" />
     </head>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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