简体   繁体   English

我不能在404页面上发送HTTP 404错误吗?

[英]Can I NOT send a HTTP 404 error on a 404 page?

So basically I have my website and I'm trying to make it compatible with everything. 所以基本上我有我的网站,我正在尝试使其与所有内容兼容。

You go to the page: /Page_Name 您转到页面:/ Page_Name

But the page Page_Name does not exist but the 404 page is what handles the the request. 但是页面Page_Name不存在,但是404页面是处理请求的页面。 I'm almost using it as a PHP GET command. 我几乎将它用作PHP GET命令。

Web browsers work, but some other scripts fail because HTTP returns 404. Web浏览器可以工作,但是其他一些脚本失败,因为HTTP返回404。

How can I fix this without creating files for every page? 如何在不为每个页面创建文件的情况下解决此问题? Can I use the .htaccess file to make the "GET" command work without "?Name=Page_Name" ? 我可以使用.htaccess文件使“ GET”命令在没有“?Name = Page_Name”的情况下工作吗?

You can use this rule as catch all rule in your DOCUMENT_ROOT/.htaccess file: 您可以使用此规则作为DOCUMENT_ROOT/.htaccess文件中的所有规则

DirectoryIndex index.php
RewriteEngine On
RewriteBase /

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

Then inside index.php you can use $_SERVER['REQUEST_URI'] to check what the original URI is. 然后在index.php您可以使用$_SERVER['REQUEST_URI']检查原始URI是什么。

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

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