This simply changes the dynamic parts of url, such is page.php?var=$user.
First is mod_rewrite in .htaccess file:
This means that from the part $1 will be token if the content is lower-upper case letters and numbers and set it after RewriteBase which is domain.
Next is setting or changing the links through the script such as ./page/var instead ./page.php?var=var
But if you have done script and just want to change this way, for example, for users, it is much easier to write a redirect page to avoid editing the whole script.
That is pretty much like this.
Make redirect.php with:
With .htaccess code:
Thats it. And if you have some other GET vars across this rewrite, you would have to add it in both parts.
First is mod_rewrite in .htaccess file:
Code:
RewriteEngine on Options +FollowSymLinks RewriteBase / RewriteRule ^([0-9Aa-zZ]+)/$ page.php?var=$1 [L]
Next is setting or changing the links through the script such as ./page/var instead ./page.php?var=var
But if you have done script and just want to change this way, for example, for users, it is much easier to write a redirect page to avoid editing the whole script.
That is pretty much like this.
Make redirect.php with:
PHP Code:
$url = !empty($_GET['query']) ? (preg_match('/^[a-z0-9]+$/iD', $_GET['query']) ? $_GET['query'] : null) : null;
if (isset($url)) {
$url = trim($url);
if (get_magic_quotes_gpc()) $url = stripslashes($url);
$query = mysql_query('SELECT * FROM `users` WHERE `nick` = "'.mysql_real_escape_string($url).'" LIMIT 1');
if (mysql_num_rows($query)) {
$id = mysql_fetch_array($query);
$go = (int) $id['id'];
header('Location: ./index.php?id='.$go.'');
exit;
} else {
header('Location: /');
exit;
}
} else { exit('Redirect Error'); }
Code:
RewriteEngine on Options +FollowSymLinks RewriteBase / RewriteRule ^([0-9Aa-zZ]+)/$ redirect.php?query=$1 [L]
Comment