(Sorry if this is a repeat question, I had a hard time thinking of how to search for it, and just came up with thousands of results about how to make 404s work.)
I’m trying to build a PHP website that would roughly follow the form: http://www.example.com/user/MrPoopPants
And I was wondering the best solution for that. In also trying to figure out how URL shorteners redirect, one website suggested sending every request through a 404, and have the 404 error page assess the data with $_SERVER['REQUEST_URI']
With that, you could just preg_split, and ask a database if there is a user named MrPoopPants, then just build your site with PHP based on includes and he database.
The two problems I don’t like with this are: I am using a 404 for every page in the website, that seems like a really bad thing; I am also relying on a single php file for the entire website, which seems like bad form.
What would the best way to go about this be? EDIT: That is, I realize this is a bad practice, what is the solution? How do I detect the URL information without having it redirected to a 404? How do I set up a page so that when you do /user/manboy it knows to let /user/user.php read the URL and build the page?
You are essentially asking about URL rewriting. An excellent tutorial for beginners explaining all the important bits and bytes of
mod_rewritecan be found here.The PHP part of handling rewritten requests is I am afraid PHP 101 which no one can simply “explain” to you. You need to have a specific question about a very specific problem in order for people to be able to actually help you.