如果页面不存在则不重定向,只显示没有其他页面数据的代码

Page not redirecting if not exists, just shows code with no data from other page

所以我有一个问题,如果 url 实际上不存在,我不会被重定向到 404,而是显示来自另一个页面的代码。

所以我有一个名为 viewpost.php 的页面,它通常只有在 viewpost.php?id=slug-text-of 这样的情况下才有效-post,但是如果你说去 bloggg.php,它不存在,它会告诉你视图post 页面代码,就像您在没有任何 GET 变量的情况下查看它一样。因此,URL 将显示 bloggg.php,但显示来自 viewpost.php 的代码,就好像没有任何内容会传递给它并显示此 empty page with no data to fill it

下面是我的.htaccess

RewriteEngine On
ErrorDocument 404 http://www.example.com/404.php
RewriteBase /
RewriteRule ^c-(.*)$ viewcat.php?id= [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ viewpost.php?id= [QSA,L]

实现目标的最佳方式:

RewriteEngine On
ErrorDocument 404 http://www.example.com/404.php
RewriteBase /
RewriteRule ^cart/([0-9]*)$ viewcat.php?id= [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^post/([0-9]*)$ viewpost.php?id= [QSA,L]