Say you have following structure:
index.php
pages
page1.php
page2.php
pageN.php
So make use of $_GET
to get the page name:
index.php
if(isset($_GET['page']) && !empty($_GET['page'])) {
$pagename = $_GET['page'];
if(file_exists("pages/$pagename.php")){
include_once "pages/$pagename.php";
}
}
When URL has index.php?page=page1
, it checks for page1.php
inside pages folder. If file exists, it includes that file inside index.php
. Similarly for other pages.
This is a simple outline idea though. You can develop further, introduce validations. And again, use pretty URLs to make it better for SEO. It can be done by adding few lines to .htaccess
file. URL then will be domain.com/page1
or something as you configure.