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


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

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

所以我有一个名为viewpost.php的页面,它通常只有在喜欢view post.php时才能工作?id=post的slug文本,但如果你说去blogg.php,它不存在,它会向你显示viewpost页面代码,就像你在没有任何GET变量的情况下查看它一样。因此,URL将显示blogg.php,但显示viewpost.php中的代码,就好像没有任何东西传递给它一样,并显示没有数据的空页面填充

下面是我的.htaccess

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

实现目标的最佳方式:

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