繁体   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