Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

throw 404 error with .htaccess file and php

I’ve got url like www.web.com/home and 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 www.web.com/asd, .htaccess will throw 404 error and direct page-not-found.html file

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading