.htaccess
RewriteEngine On
RewriteRule register index.php?mode=register
RewriteRule login index.php?mode=login
index.php
<?php
if ( isset ( $_GET['mode']) && ( $_GET['mode'] == 'register' ) ) {
include('includes/register.php');
} elseif ( isset ( $_GET['mode']) && ( $_GET['mode'] == 'login' ) ) {
include('includes/login.php');
}
?>
This is my current method (thanks to @TROODON).
Is there an easier way, maybe using key-value arrays to store all the possibilities for the various pages that index.php will call?
Thanks
For your
.htaccessyou can do this:However, don’t change your PHP code to just
includewhatever you are getting from$_GET['mode']! This will allow users to include at will.You could adjust your PHP code like so:
PS: The two
RewriteCond‘s make sure the url is not an existing file or folder (i.e. if you have a folderimagesthen site.com/images will still go to that folder instead ofindex.php?mode=images.