Created
April 8, 2012 09:02
-
-
Save geirarne/2336160 to your computer and use it in GitHub Desktop.
mod_rewrite test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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