Another very beginner website question. So looking at the file structure behind a simple php site:
File structure for PHP-based website
Folder/File Structure Conventions?
Suggest using a structure similar to:
htdocs/
/Assets/
/CSS
/JS
/func/func.php
_newpost.php
tags.php
index.php
For SEO I believe that more ‘logical’ URL’s are preferred for subcategories of content.
eg. www.example.com/tags.php?t=celebrity
is less preferable to:
www.example.com/tags/celebrity
In terms of the URL – I could put the tags.php file inside htdocs/tag OR I could use mod_rewrite to give the desired effect. This said, moving .php files inside subfolders is going to cause problems when ‘including’ func/func.php and any other ‘actions’ such as _newpost.php.
Question – Is there a convention to where PHP files go? should they all be in the root? For _newpost.php – a file that carried out and action and redirects. Is there a convention to where these all should sit? Then should mod_rewrite deal with the ‘looks’ of the URL?
Many thanks – ever grateful, Matt
In terms of the URL – You don’t need to place tags.php inside anywhere specific, mod_rewrite has quite a lot capability, for example the effect you desire.
Moving into subfolders won’t cause you problems neither as long as you plan your structure well, one important thing is to define DOCUMENT_ROOT in the php.ini, so you can access your site’s root through $_SERVER[‘DOCUMENT_ROOT’]; when doing includes inside of includes, this way you won’t mess up.
Question – There is not actually a convention as far as I know, you can organize the files the way you think is more convenient and clean/friendly for you and or future developers. although the structure you showed is pretty common.
So yes, normally the friendly URL’s are dealt with mod_rewrite, and not with the directories, as you can set the rewrite rules as you desire.