- This topic is empty.
-
AuthorPosts
-
February 10, 2015 at 10:13 am #195488bearheadParticipant
Hi, I am in the process of updating a website with nearly 400 separate page. I have read that using your index.php file as a single point of entry for the site is a good way to vastly improve maintainability on large sites.
However I’m not very experienced with php, and I’m not quite sure what that means or how to implement it. Does the index.php contain a script that loads in content, based on what url the user is viewing? If so what would such a script look like? I have searched a bit, but I can’t really find any explanations that I could understand.
Thanks for the clarification.
February 10, 2015 at 11:18 am #195495AnonymousInactiveI’m not quite sure what that means or how to implement it. Does the index.php contain a script that loads in content, based on what url the user is viewing? If so what would such a script look like?
Before coding anything, think through what those 400 pages have in common. The point of a single point of entry is not that it is good in itself, but that you are trying to separate content / data from how it is presented. For example, a blog site might have 400 posts, but each post would be essentially the same. They each have a title, a date, an author, and some content.
An important first question – have you used databases before and are you currently using one?
March 20, 2015 at 7:27 am #198592Taufik NurrohmanParticipantI was stuck thinking that the links would still be pointing to specific files and was like- how the hell is code on index.php going to matter when the user clicks a link and goes to a different page!?
Use
.htaccess
to remove theindex.php
part in URL. Query string will be used as the fake URL path. When you click on a link, you are not going to any different pages. It’s just the sameindex.php
page with different query strings.# Rewrite `http://my_website.com/index.php?foo/bar` to `http://my_website.com/foo/bar' <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1 [L,QSA] </IfModule>
Here you can use the query string for loading different template to the
index.php
using PHPinclude
orrequire
.Something like this:
<?php $q = str_replace('?', "", $_SERVER['QUERY_STRING']); if (strpos($q, 'path/to/file-1') === 0) { include '../template-1.php'; } elseif (strpos($q, 'path/to/file-2') === 0) { include '../template-2.php'; } else { include '404.php'; }
This barebones should be able to help you to understand: https://github.com/tovic/cms-starter
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.