簡體   English   中英

將 URL 參數添加到 Htaccess 重定向錯誤文檔

[英]Add URL Parameter To Htaccess Redirect ErrorDocument

在我的網站上,當用戶導航到無效的 url 時,我仍然想顯示他正在尋找的內容,但是當我重定向到我的錯誤時。通過.htacceserror.php丟失了錯誤的 ZE6B391A8D2C4D45903DZA23。

我正在使用它來重定向(.htaccess):

ErrorDocument 404 https://www.mywebsite.com/error.php

我想要的是將錯誤的 URL 作為 URL 參數添加到重定向的末尾。

For examplewhen the user navigates to this URL https:www.mywebsite.com/this-does-not-exist I want that to reflect in my error.php as well and add the last part as URL paramater. URL 應如下所示:

https://www.mywebsite.com/error.php?url=this-does-not-exist

I already tried doing ErrorDocument 404 https://www.mywebsite.com/error.php?url=$1 and I also tried ErrorDocument 404 https://www.mywebsite.com/error.php [L] both versions did not give我想要的結果。

如何將錯誤的 url 添加到 ErrorDocument 重定向,作為htaccess中的 url 參數?

最簡單的方法是使用文檔根目錄而不是.htaccess IE 中的主機:

ErrorDocument 404 /error.php

然后在您的 PHP 腳本error.php中,您只需使用即可獲得當前的 URL

$url = $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI];
echo "The page $url you are trying to reach doesn't exist!";

一直保持當前的 URL

https://www.mywebsite.com/this-does-not-exist

顯示在 URL 欄中。

暫無
暫無

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

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