.htaccess htaccess mod_rewrite q,允许用户查看不存在的页面

.htaccess htaccess mod_rewrite q,允许用户查看不存在的页面,.htaccess,.htaccess,因此,我在.htaccess中为我的mod_重写提供了以下内容 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]*)$ /?a=$1 [L] RewriteRule ^product/([^/]*)$ /product.php?p=$1 [L] 让我用/help代替.index.php?a=help,但问题是,如果有人访问/bl

因此,我在.htaccess中为我的mod_重写提供了以下内容

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /?a=$1 [L]
RewriteRule ^product/([^/]*)$ /product.php?p=$1 [L]
让我用/help代替.index.php?a=help,但问题是,如果有人访问/blahblah is没有给出错误,它只会显示一个空白的索引页,除了徽标、侧边栏和空白内容空间之外,没有任何内容


有没有办法阻止这一切?我本来打算使用php if(),但这似乎很麻烦,因为每次添加页面时我都必须这样做。有没有使用.htaccess的方法?

您必须在这里使用php。您的
index.php
读取
$\u GET['a']
变量并确定要呈现的内容。但是mod_rewrite对
index.php
文件中哪些内容是可渲染的,哪些内容不是可渲染的一无所知


实现将取决于
index.php
的编写方式。如果找不到由“a”参数表示的页面,则需要
index.php
返回404结果。在htaccess中无法做到这一点。

您是否定义了ErrorDocument 404、500等。。?