我不能在 404 页面上发送 HTTP 404 错误吗?
Can I NOT send a HTTP 404 error on a 404 page?
所以基本上我有我的网站,我正在努力使其与所有内容兼容。
您转到页面:/Page_Name
但是页面 Page_Name 不存在,但是 404 页面是处理请求的页面。我几乎将其用作 PHP GET 命令。
Web 浏览器可以工作,但其他一些脚本因 HTTP returns 404 而失败。
如何在不为每个页面创建文件的情况下解决此问题?我可以使用 .htaccess 文件使 "GET" 命令在没有 "?Name=Page_Name" 的情况下工作吗?
您可以在 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]
然后在 index.php
里面你可以使用 $_SERVER['REQUEST_URI']
来检查原始 URI 是什么。
所以基本上我有我的网站,我正在努力使其与所有内容兼容。
您转到页面:/Page_Name
但是页面 Page_Name 不存在,但是 404 页面是处理请求的页面。我几乎将其用作 PHP GET 命令。
Web 浏览器可以工作,但其他一些脚本因 HTTP returns 404 而失败。
如何在不为每个页面创建文件的情况下解决此问题?我可以使用 .htaccess 文件使 "GET" 命令在没有 "?Name=Page_Name" 的情况下工作吗?
您可以在 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]
然后在 index.php
里面你可以使用 $_SERVER['REQUEST_URI']
来检查原始 URI 是什么。