Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在地址栏中保留输入错误的URL,同时仍向用户显示未找到的页面?_Php_.htaccess_Redirect_Http Status Code 404 - Fatal编程技术网

Php 如何在地址栏中保留输入错误的URL,同时仍向用户显示未找到的页面?

Php 如何在地址栏中保留输入错误的URL,同时仍向用户显示未找到的页面?,php,.htaccess,redirect,http-status-code-404,Php,.htaccess,Redirect,Http Status Code 404,下面是我正在寻找的一个例子: 如果您访问上述链接,您不会被重定向到未找到的页面。地址栏中的原始URL保持不变,但页面内容仍显示未找到的消息。我该怎么做 目前,我在我的.htaccess中使用了以下行,没有其他内容 ErrorDocument 404 https://mywebsite.com/not-found.php 我是否需要删除这一行,还是需要执行其他操作以实现类似SitePoint示例的not found?示例url在.htaccess文件中使用url重写。您可以将所有与现有文件不对应

下面是我正在寻找的一个例子:

如果您访问上述链接,您不会被重定向到未找到的页面。地址栏中的原始URL保持不变,但页面内容仍显示未找到的消息。我该怎么做

目前,我在我的
.htaccess
中使用了以下行,没有其他内容

ErrorDocument 404 https://mywebsite.com/not-found.php

我是否需要删除这一行,还是需要执行其他操作以实现类似SitePoint示例的not found?

示例url在
.htaccess
文件中使用url重写。您可以将所有与现有文件不对应的URL发送到错误文档:

RewriteEngine On

#if the request is an existing file, show the file
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

#else show your 404 page
RewriteRule ^(.+)$ /not-found.php [QSA,L]
另外,确保
not found.php
页面发送正确的404头:

header("HTTP/1.1 404 Not Found");