Skip to content

Instantly share code, notes, and snippets.

@geirarne
Created April 8, 2012 09:02
Show Gist options
  • Save geirarne/2336160 to your computer and use it in GitHub Desktop.
Save geirarne/2336160 to your computer and use it in GitHub Desktop.
mod_rewrite test
Options +FollowSymLinks
RewriteEngine On
# handle the rewrite
RewriteCond %{REQUEST_URI} ^/.*/.*/.* [NC]
RewriteRule (\w+)/(\w+)/(\w+) /index.php?page=$1&subpage=$2&mod=$3 [L,QSA]
<?php
// config
$get_keys = array('page','subpage','mod');
// get a (somewhat) clean variable from the GET parameter
function get_var($key)
{
if (isset($_GET[$key]) && !empty($_GET[$key])) :
return htmlspecialchars($_GET[$key]);
else :
return 'NOT SET';
endif;
}
// get an indexed array with data from the URL
function get_url_data($get_keys)
{
$server_vars = array();
foreach ($get_keys as $key) :
$server_vars[$key] = get_var($key);
endforeach;
return $server_vars;
}
// init page
$server_vars = get_url_data($get_keys);
?>
<html>
<h1>mod_rewrite test</h1>
<table>
<tbody>
<?php
foreach ($server_vars as $key => $value) :
?>
<tr>
<td><?php echo $key; ?></td>
<td><?php echo $value; ?></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment