I have a small website. It’s .htaccess file is like this:
RewriteEngine On
RewriteBase /site/
RewriteRule ^(.+)$ index.php [QSA,L]
So it redirects all the URLs to ‘index.php’. I can get the requested URL and act accordingly :
$uri = $_SERVER['REQUEST_URI'];
switch($uri)
{
case 'index':
LoadIndex();
break;
case 'about':
LoadAbout();
break;
case 'Posts':
LoadPosts();
break;
default:
LoadNotFound();
}
Say I want to use $_GET[] in Index page. That changes the URL, so it fails to load the page.
How can I do that? How can I route my site without affecting $_GET[] variables in URLs?
$_SERVER[REQUEST_URI]will be/index.phpand notindex.$_SERVER[REQUEST_URI]also includes theQUERY_STRING. So, it might be/index.php?var1=abc&var2=def.If you need only the URI path, try
PHP_SELForSCRIPT_NAME. But keep in mind, that these will be/index.phptoo, including/and.php.You don’t need
QSAin yourRewriteRule. From RewriteRule DirectiveThis means, the
$_GETvariable is available in your PHP script as before.