I’ve been wondering for quite a while how do you set up php so that you instead of getting content from tables w/ get like www.mysite.com/index.php?id=1 you get them by www.mysite.com/pages/news-1.php
I have no idea how else to make up this question; but do I have to manually create new pages and put them in directories then link the page/ID via db or is there another way with mysql only.
2
Answers
With URL rewriting, you need to route all page requests to your “front controller” / index.php. Then you use a router to send that request to a particular controller method. In that method, you would grab the request’s path (eg. /postname). Your posts database table would have a “slug” field. You then query the database for the “posts” result that contains the slug “postname”.
Please check out this tutorial to learn how to make a custom framework, it’ll give you the amount of background information that might shed some light on how this all works: http://symfony.com/doc/master/create_framework/index.html
Create a file with name .htaccess in your web root directory. And paste these lines into it (Tested):