if I have a categories section of my website.
I notice some websites are built so categories are under categories.php, and some websites are built so categories are under a folder.
Example >
www.example.com/categories.php
vs
www.example.com/categories/
Is there a benefit or con to doing either of those 2 ways, is having each page of a site in a separate folder just used for keeping things organized better?
What are the pros and cons of both.
Since you will most likely be dealing with dynamic content you will find that under the hood most apps are actually configured to use a file such as
categories.php
under the hood.In other words - requests to
categories
is routed to/categories.php
behind the scenes.I am deliberately leaving some stuff out here to not over-complicate matters but hope that makes sense so far.
The most common reasons for this are that by emulating a folder structure you...
1 - ...hide details about how you built the site.
So in your case you obscure that you are using php. This is good for security purposes because any potential attacker now no longer knows what technology you are using, making it harder to successfully mount an attack.
This is also good for your normal users who won't know, care or understand what this
.php
extension is (or what an extension is for that matter). So by hiding it you also make your URL more readable, which leads me to the next point.2 - ...make your URLs easier to read.
Consider this example:
/categories.php?action=edit&id=43
vs
/categories/shoes/edit
As you can see the version that has things in "folders" is much easier to read and even my Gran could make an educated guess as to what that page might do.
So doing this is great for your users but also for search engines.
By formatting urls in such a way services like google better understand what you are doing and thus end up indexing your resources more precisely.
Hope this helps.