Is it better to handle friendly/clean/pretty URLs with mod_rewrite or a language like PHP?

前端 未结 5 822
挽巷
挽巷 2021-02-04 14:55

I\'m developing my first decent-sized PHP site, and I\'m a bit confused about what the \"right way\" (assuming there ever is such a thing) to handle clean/friendly/pretty URLs i

5条回答
  •  醉话见心
    2021-02-04 15:55

    Option 1 (.htaccess and several .php files) was often used "in the past" ; now, I see option 2 (every request going through one .php file) used a lot more.

    The main advantages I see with option 2 are :

    • you can add / modify any kind of URL without having to change any physical file like .htaccess
      • which means the format of the URLs can be configured in the admin section of your application, for example
    • you only have one entry point to your PHP code.
      • which means everything goes though index.php : if you need some code executed for all requests, put it there, and you're sure it'll always be executed.
      • That's used a lot with MVC frameworks, for instance.


    A couple of years ago, I would have gone with option 1 ; now that I use MVC and Frameworks, I always go with option 2.

提交回复
热议问题