-1

所以我的 .htaccess 中有以下内容用于我的 mod_rewrite。

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 没有给出错误,它只会显示一个空白的索引页面,除了徽标,侧边栏之外什么都没有和空白内容空间。

任何想法如何阻止这种情况?我打算使用 php if() 但这似乎很麻烦,因为我每次添加页面时都必须这样做。.htaccess 有什么办法吗?

4

1 回答 1

1

你必须在这里使用 php。您index.php读取$_GET['a']变量并确定要呈现的内容。但是 mod_rewrite 对文件可呈现或不可呈现内容的了解为零index.php

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

于 2013-07-12T05:47:30.017 回答