Skip to content

Instantly share code, notes, and snippets.

@billjohnston
Forked from anonymous/.htaccess
Last active December 10, 2015 03:58
Show Gist options
  • Save billjohnston/4378304 to your computer and use it in GitHub Desktop.
Save billjohnston/4378304 to your computer and use it in GitHub Desktop.
PHP: Simple permalinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#If you want any directories ignored uncomment and edit line below
#RewriteRule ^(dash|admin)($|/) - [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#If in sub directory, add before index.php (ex: admin/index.php)
RewriteRule . index.php [L]
</IfModule>
<?php
$pageArray=explode('/',$_SERVER['REQUEST_URI']);
//If in sub directory, change to $pageArray[2] etc.
switch($pageArray[1]){
case "":
include('header.php');
include('home.php');
include('footer.php');
break;
case "pageExample":
include('header.php');
include('pageExample.php');
include('footer.php');
break;
default:
include('header.php');
include('404.php');
include('footer.php');
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment