I'm looking to achieve similar functionality on my site as facebook does for its pages section. Basically I want users to be able to navigate to:
www.mysite.com/school123
Then behind the scenes I would be able to locate 'school123' using URL with PHP, then I can find the correct path in the database and redirect to the correct path (example: www.mysite.com/pages/schools/school123/index.php ). Problem is as the page doesn't exist I get a 404 error.
My question is should I look at modifying the 404 page to do the DB lookup & redirect my page or is there a better way of doing this?
Thank you in advance
Your webserver has to take care of that and pass the arguments to PHP.
If you're using Apache, checkout this:
In case of nginx:
Modifying the 404 page is one way to do it, then obviously overwriting the 404 Header using PHP. But this isn't the most practical of ways, I am making the assumption of Apache; as Claudio Bredfeldt said: http://httpd.apache.org/docs/current/mod/mod_rewrite.html and then after your DB Lookup for the Pointer/Reference to the file/data you should use http://www.php.net/manual/en/function.readfile.php to quickly return it on the initial URL without a redirect. This will lower overhead.
1> you can pass school and 123 as parameter to your url as somepage.php?t=shool&n=123, and depending on parameter you can redirect.
2>in your root folder you can make folder as school123 and in that you can have index.php file which will redirect to www.mysite.com/pages/schools/school123/index.php