Better to have individual pages or folder for different section of website

67 views Asked by At

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.

3

There are 3 answers

2
Bananaapple On BEST ANSWER

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.

3
jonathan.ihm On

Your first example, you are specifically asking for a file. The second example you are requesting a route, which may or may not be a folder. It could also be a file as well. It depends on how the server will handle your request. In my opinion, it's better to do it with the second example to:

  1. Obfuscate your tech stack
  2. If your resource changes, you won't need to edit your link and it will save your time, you just need to make a back end change instead of both front and back end
0
Serdar Saygılı On

Your clients would not want the see web page extension like .html, .php and so on. Moreover, think one user writes the full URL to go to the page. It is also a bother for the client.

And think about it, for now, you are serving your site in Php. But what about when you decide to serve your site with any other language. Then if you change your links, older links would be broken if you don't change then this means you continue to use the ".php" extension. Which is not something when you do not use Php.