How to rewrite urls with GET variables?

I have a site that uses GET variables to determine what to display.

@session_start();
@extract($_GET);
@extract($_POST);
.
.
.
if (!$menu) { include("home.php"); }
if ($menu=='buy') { include("buy.php"); }
if ($menu=='invalidbuy') { include("invalidbuy.php"); }
if ($menu=='buydone') { include("buydone.php"); }
.
.
.

      

I think I need to use a .htaccess file to rename my urls from "/index.php?menu=faq" to "/ faq". How can i do this?

0


a source to share


1 answer


You can use the following rule , to rewrite any request path, for example /

foobar

, to /index.php?menu=

foobar

:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]+$ index.php?menu=$1 [L]

      



An additional directive RewriteCond

ensures that only non-existent files ( !-f

) are overwritten .

+1


a source







All Articles