当用户输入错误的URL PHP时如何重定向到404错误页面

时间:2019-07-19 14:55:18

标签: php .htaccess http-status-code-404 file-not-found

我正在建立一个静态的HTML网站。用户首次进入我的网站时,首先将他/她重定向到文件夹index.php上的localhost/creative,并在使用index.php处理require_once之后提取了所有HTML文件,例如localhost/creative/themes/目录中的header.php。在整个过程中,如果用户输入了错误的URL,则我有一个问题将他/她重定向到位于目录localhost/creative/themes/404.php的404错误页面。

在我的.htaccess文件中

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /creative/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /creative/ [L]
</IfModule>

我尝试使用Error Document 404 /themes/404.php,但是它不起作用。如果404.php错误,谁能告诉我如何将我网站上的用户重定向到url?我希望处理在php中。

0 个答案:

没有答案