throw 404 error with .htaccess file and php

I’ve got url like http://www.web.com/home and http://www.web.com/about with .htaccess file:

RewriteEngine On
Options +FollowSymLinks
ErrorDocument 404 http://www.web.com/page-not-found.html
RewriteRule "home" "index.php?c=home&m=main"
RewriteRule "about" "index.php?c=home&m=about"

If I type something like http://www.web.com/asd, .htaccess will throw 404 error and direct page-not-found.html file

But, If I type http://www.web.com/homesss or http://www.web.com/about/a/b/c, the .htaccess will not throw the 404 error

How do I fix that? I use pure PHP

>Solution :

Use meta characters in rewrite rule to 1:1 match:

^ — Matches the beginning of the input

$ — Matches the end of the input

[L] — Flag last to stop processing rule after match

RewriteEngine On
Options +FollowSymLinks

ErrorDocument 404 http://www.web.com/page-not-found.html

RewriteRule ^home$ index.php?c=home&m=main [L]
RewriteRule ^about$ index.php?c=home&m=about [L]

Leave a Reply