Core Wiki

PHP

URL Rewrite with GET variables

In order to rewrite links such as domain.com?one=var1&two=var2 into domain.com/var1/var2 with Apache, set .htaccess file to

RewriteEngine On
RewriteBase / 
RewriteEngine On Options All -Indexes RewriteBase /directoryname/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
 
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

One can now access the variable content as:

$parca = explode("/", $_GET["url"]); 
 
echo $parca[0]; //var1
echo $parca[1]; //var2