Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我使用以下规则声明时:
RewriteRule ^foo foo.php
当我访问localhost/foo成功时显示foo.php,但是当我访问localhost/foofakeor时localhost/fooanythingelse,它仍然显示 foo.php。如何防止这种情况并改为显示 404 错误页面?
localhost/foo
foo.php
localhost/foofake
localhost/fooanythingelse
PS:我知道这个问题但是我在这里尝试做的是不同的。
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