What is a good way to have a SEO URL system built up in PHP?

前端 未结 3 1264
遥遥无期
遥遥无期 2021-02-11 07:16

I want to have \"pretty\" and SEO oriented URLs in my site.

I\'ve build up my own tiny framework for this site and almost everything is complete now.

One thing I

3条回答
  •  面向向阳花
    2021-02-11 07:31

    Directing everything to index.php and then routing from there is a good, clean way to do it. I have something very similar, I:

    1. Route everything to index.php in .htacess.
    2. In index.php I split the url by '/' to get an array
    3. The first element of the array is the name of the class to call.
    4. The second element is the function of the class to call.
    5. If needed, remaining elements are parameters.

    For example, browsing to:

    www.blah.com/shop/browse/cakes

    Would call index.php, which would include shop.php and instantiate a class called Shop. Would try to call a function on Shop called browse and would pass it a parameter of "cakes".

    This is a simplified example but you get the idea. Convention over configuration makes the URLs and the code clean.

提交回复
热议问题