繁体   English   中英

使用Htaccess和PHP将用户输入的URL传递到404页面

[英]Passing URL entered by user to 404 page with Htaccess and PHP

我有一个支持PHP和htaccess的网站。
基本上,我想将用户(导致404)输入的URL传递给404页面本身。
有什么办法吗?

在您的.htaccess文件中添加以下规则。

 ErrorDocument 404 /error.php

error.php文件中。

<?php // error.php
echo $_SERVER["REQUEST_URI"]. " doesn't exists. Sorry!";
?>

只需在.htaccess文件中添加以下内容(其中404.php是您的错误页面)

ErrorDocument 404 /404.php

您可以通过在.htaccess中添加以下规则来做到这一点。

 ErrorDocument 404 /404.php

在您的404.php中,您可以编写

<h3>
Page Not Found.
</h3>
<div>
     <p>Apologies, but the page you requested could not be found.</p>
     <ul>
        <li>You may have mistyped the page address.</li>
        <li>You may have clicked on a link that has not been updated.</li>
        <li>We have recently changed our site structure and the page has been moved to new location.</li>
    </ul>
</div>

您可以设置样式以使其正确显示。

希望这可以帮助 :)

暂无
暂无

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

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