Mobile app version of vmapp.org
Login or Join
Kevin317

: How to handle non-existent subdirectories? I have a dynamic website with friendly URLs. Example: Instead of /user.php?id=123, I have /user/123 Instead of /index.php?category=fishes, I have /fishes

@Kevin317

Posted in: #Apache2 #Configuration #Php

I have a dynamic website with friendly URLs. Example:


Instead of /user.php?id=123, I have /user/123
Instead of /index.php?category=fishes, I have /fishes


But, how do I handle non-existent subdirectories such as /about/123? Currently it gives a 200 success instead of a 404 not found error. Is there a way to deal with non-existent subdirectories in Apache config and at the same time allow for friendly URLs? Or do I have to handle this individually for each PHP script?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Kevin317

1 Comments

Sorted by latest first Latest Oldest Best

 

@Cugini213

If you ensured all the wanted folder names were present in the regex list then all others could be redirected to a 404 page using this .htaccess script:

# If friendly URL dynamic folder not present in URL then respond HTTP 404
RewriteRule ^(user|fishes) - [R=404]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme