0

当我使用以下规则声明时:

RewriteRule ^foo foo.php

当我访问localhost/foo成功时显示foo.php,但是当我访问localhost/foofakeor时localhost/fooanythingelse,它仍然显示 foo.php。如何防止这种情况并改为显示 404 错误页面?

PS:我知道这个问题但是我在这里尝试做的是不同的。

4

1 回答 1

1

You need to tell the server to only redirect an URL that doesn't have any text following the "foo", by adding an "end string" sign ($).

RewriteRule ^foo$ foo.php

To make it also work for a trailing slash, add another line:

RewriteRule ^foo/$ foo.php
于 2013-01-09T15:13:49.713 回答