Best way to structure a site

I was reading through Kevin Yanks latest book PHP & MYSQL NOVICE TO NINJA and it got me to thinking.
In his example it seems each page has its own folder. Surely thats just more work.
The effect is a url that looks something like this
[noparse]www.mysite.com/about/[/noparse]
instead of the traditional
[noparse]www.mysite.com/about.php[/noparse]

Would it not be easier to keep all pages within a root folder and just use htaccess to change the URL?
One problem that annoys me is nice urls i hate having to use [noparse]www.mysite.com/view-video.php?id=12[/noparse]
I would much rather use [noparse]www.mysite.com/view-video/video-name.php[/noparse]

Does Kevins structure offer an easier way to do this or would the tradition method using htaccess be the best?

I found the problem of saving all main files in the root directory makes it extremely difficult to upgrade to a new version or to be able to work on an separate online test version.

I have adopted the practise of storing all program files in a [noparse]www.mysite.com/version_XXX/[/noparse] folder and including the [noparse]www.mysite.com/version_XXX/index.php[/noparse] in the root index.php. Complete test or future versions can be easily selected by changing a single line in the root index.php file.

file: [noparse]www.mysite.com/index.php[/noparse]



   #include './version_2011-11-11/index.php'; # first version

   include './version_2012-07-11/index.php'; # latest version


Also if the latest version develops some undesirable undocumented features the previous version can be swapped back while the features are eliminated :slight_smile:

Im not fully following your method.

In mysite.com/ you have only one page that includes the rest?

Could you show me a stucture example like

index.php

about.php

images/

[INDENT]img1.jpg[/INDENT]

[INDENT]img2.jpg[/INDENT]

includes/

[INDENT]db-con.php[/INDENT]

Thanks

Actually, that’s pretty much the way you store your files: you create meaningful folders and you store the files there.

[noparse]www.mysite.com/about/[/noparse] translates, by default, as far as Apache is concern, and if your site is in PHP, to [noparse]www.mysite.com/about/index.php[/noparse].

And if at some point you’d just want to go with Python at server side… and somebody was bookmarking this page? Broken links are not making for happy users.

No.

Your desktop storage scheme is also folders and subfolders, having, hopefully, meaningful names, containing your files. Why this should be any different?

URL is folder path.
It’s not the Unix “/” standard folder separator, it’s [noparse]www.*.com[/noparse] that’s throwing you off, probably.

You mean to say pretty urls. [noparse]www.mysite.com/view-video.php?id=12[/noparse] is this [noparse]www.mysite.com/view-video/12[/noparse]. PHP or Python, or Java, the same path. User friendly & SEO goody.

It’s not Kevin’s structure, it’s normal folder and subfolder way of keeping files since… a long long time.

Why would you do that? Test versions belong an a local development server.

Besides, the good that comes from not storing the files in the root, is security related.

[QUOTE=itmitică;5149712]
Why would you do that? Test versions belong an a local development server.

Besides, the good that comes from not storing the files in the root, is security related.
[/QUOTE]

>>> Test versions belong an a local development server.
The local test versions are validated then uploaded and personally tested again.
After online validation is complete the test version is made live and log error/warning messages monitored.

>>> Besides, the good that comes from not storing the files in the root, is security related.
I am led to believe that source files should be stored above the root for even better security.

Using tried and tested PHP Frameworks make it easy to store both system and application files above the root.

By adopting the above practice changing to another version means the site is offline only momentarily while the new base file route index.php file is updated.

Reminds me of an old “Under Construction” avatar…

Creating folders to put your code in is a pretty quick and easy thing, so if you’re just trying to get rid of the .php extensions folders is the simplest way.
What you’re really looking for is a routing mechanism so that you can work with pretty url’s and pass the different parts of the url through as strings.

I’m not sure what the best method for PHP is, though I think most frameworks will help you to do it. These might point you in the right direction.
http://stackoverflow.com/questions/1316040/how-to-implement-url-routing-in-php-im-a-newcomer-to-know-this-concept-help-me
http://bakery.cakephp.org/articles/Frank/2009/11/02/cakephp-s-routing-explained

John, I’ve never seen that done before. If it’s working for you keep using it, but I think most people just keep versioning under control in source control and not in directories. Versioned apps / sites are painful to work with anyway, I’d always opt for One Version To Rule Them All.

[QUOTE=itmitică;5149711]Actually, that’s pretty much the way you store your files: you create meaningful folders and you store the files there.

URL is folder path.

It’s not Kevin’s structure, it’s normal folder and subfolder way of keeping files since… a long long time.[/QUOTE]
No, URL’s do not mean folder paths.
That’s quite often the case, but they aren’t directly related, it’s often not the best way to store them either.

URL’s should be designed for the users, make them as short, simple and explanatory as possible.
Folder structures are purely for the developers organisation, you can use whatever works for you, if you want to try putting all the files in the root directory give it a shot and see how it works. Depending on the size of the site that may work, but if you get more than 13 files you’ll want to split them out.

You’re contradicting yourself.

<hr>

URL: Uniform Resource Locator.

Example: http://www.sitepoint.com/forums/

http:// - the name of the protocol
www.sitepoint.com - a name for an IP address, a domain name that identifies a specific computer on the Internet
forums - a pathname, a hierarchical description that specifies the location of a file in that computer

<hr>

If you mean that intercepting user requests and redirecting them it means pointing to a different resource, that’s another thing altogether. URL, at its core, it is folder path, UNIX folder path to be precise.

It’s possible your wording “work on an separate online test version” gave another idea about your development process.

Exactly.

[QUOTE=itmitică;5150086]You’re contradicting yourself.

URL: Uniform Resource Locator.

Example: http://www.sitepoint.com/forums/

http:// - the name of the protocol
www.sitepoint.com - a name for an IP address, a domain name that identifies a specific computer on the Internet
forums - a pathname, a hierarchical description that specifies the location of a file in that computer

If you mean that intercepting user requests and redirecting them it means pointing to a different resource, that’s another thing altogether. URL, at its core, it is folder path, UNIX folder path to be precise.[/QUOTE]
You are wrong here, requests are made to a server and it’s up to the server how to respond to it.
The URL does not mean a file path on the server.

If you have the scripting or programming skills, you can make it redirect.
But by default, URL is folder path.

You’ve said so yourself, though in a weird way:

Default is default, scripted/programmed redirect is scripted/programmed redirect.

Of course it’s the default for most HTTP servers.

Somewhere along the line we realized that URL’s should be awesome and our code well organised too.
Ever since then URL routing has become the norm for web applications and frameworks.

“URL is folder path” hasn’t been true of any web application I’ve worked on in the last 4 years :slight_smile:


Back to the topic at hand, personally speaking MVC is the best way to structure web applications.
If it’s just a handful of PHP pages you don’t need to go to that level of complexity, but if you’re working on larger applications with a lot of moving parts the structure of MVC will help keep it under control and easy to find things.

I think at this stage putting all your pages together should be fine :slight_smile:

Routing is a process handled by a bootstrap file.
It works by catching and handling the error response for a request, when the folders and files specified in the URL’s folder path are not found.
It’s an exploit, but it boils down to the same normal UNIX folder path for a given URL.

High level web frameworks, have handy scripts to automate the creation of folder structures for the developer: CakePHP, Ruby on Rails, Django.
It’s

Convention over configuration. Use sensible defaults to avoid having to configure everything.

The developer can fiddle with the settings files and change things around, but that’s not what the high-level stands for.

Low level web frameworks however, are flexible, less intrusive and less demanding about that.
The developer gets to make its own decisions about the folder structure of its project, amongst other things.

I guess you’re more involved with high level web frameworks.
But normally, high level or low level, none of it means “putting all your pages together”.

<hr>

There is a distinction to be pointed out: a web server and an application server for a server side language.

A web server, by default, will follow the URL’s folder path and “execute” certain type of files it may find there.
An application server for a server side language is the one that may or may not receive the control after the web server decides what type of file is the one in the URL’s folder path.

Pretty much like how a user “double clicks” on a .doc file and Windows calls up on WinWord to “execute” the .doc file.
Only that the remote user doesn’t “double click” but “requests” the index.php, and the Apache web server calls up on the PHP application server to “execute” the .php file.

As you may have noticed from the other posts I use a PHP Framework which accesses the ROOT index.php file. All URL’s are routed from the “application path” which I have called ver-001, ver-002 and ver-003. In practise instead of having links in the index.php file the application version path is hard-coded.

A demo is online and also a link to the zipped source files.

http://johns-jokes.com/downloads/sp-a/website-structure/index.php

I have not used any .htaccess files to remove paths and have left that up to you to investigate URL routing :slight_smile:

if your site is more than 500 pages, i recommend directory structure per category. Very good for SEO

Mine have all been moved back to url folder = dir folder, for me it’s easier to keep things logical backend. It makes it easier for people when they update their website with FTP, as you can’t upload from iPhone and they’ve started using their phones to update their sites. By keeping the structure the same both server and client it’s easy for people with little knowledge to add media to the directories they want. I have a small default file in each directory that includes the files needed. It also makes it easier to switch between php and asp as when I last looked classic asp has nothing smilar to mod rewite, as the global.asa file only gets triggered after a file is called and .htaccess gets triggered before. I do use url rewrites for sub-sub folders though, but that is to uncomplicate the visible URL and usually it’s a category with subcategories. Most of the time they are running from the same scripts.

For me it depends how many other files I want to include within the folder. If most sub folders of a particular folder are likely to have their own media files I will give them their own folder. But if most of it’s text, or a variation of its parent then I’ll use a rewrite.

But my main reason of doing it the way I do is so I am not constrained to keep with asp or php. Once I’ve worked on .NET a bit more I may change again, as I think that has similar to .htaccess, but I doubt if I’ll deviate much, as I like to keep things categorised backend for easy navigation.