Using .htaccess all addresses are rewritten to index.php
Index.php needs to then work out which file to include. At the moment it explodes on the ‘/’ and performs a foreach to work out which file. This is causing errors.
First we get the URI.
If there is one address eg. localhost/next-page then we want to include a file with that name and the extension PHP include('content/'.$post.'.php'); and give global variables for $table as 'PAGES' and $post as 'next-page'
If there are two then the first should be considered the $table and the second the $post, and the file to include should be include('content/single-'.$post.'.php');
How do we do this?
First you need to isolate the relevant part of the URL (in this case that’s probably the path, although without your rewrite rule we don’t know). Then:
If there’s significant similarity between some cases, you can allow a fall-through from one case to the next after doing some preliminary work to normalize the situation, e.g.
Finally: if there’s lots of stuff you need to do with the items inside
$parts, you can give them names to make the code more readable using thelistconstruct: