0

When i use the following rule declaration:

RewriteRule ^foo foo.php

when I visit localhost/foo it sucessfully displayes foo.php , but when I visit localhost/foofake or localhost/fooanythingelse, it still displays foo.php. How to prevent this and display a 404 error page instead?

PS: I am aware of this question But what I am trying to do here is different.

Community
  • 1
  • 1
Peeyush Kushwaha
  • 3,453
  • 8
  • 35
  • 69

1 Answers1

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
Jenny D
  • 1,225
  • 9
  • 20