Jarek P Jarek P - 7 months ago 10
PHP Question

RewriteRule I guess?

Is it possible to change the link using RewriteRule or something in .htaccess?

www/player/?user=testuser


to

www/player/testuser


To display it I'm using:

<?php
$user = $_GET['user'];
?>
<title><?php echo $user; ?></title>

Answer

If you want to access www/player/?user=testuser

using the clean url

www/player/testuser you can use the following rule in your root/.htaccess

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^player/(.+)$ /player/?user=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^clan/(.+)$ /clan/?tag=$1 [L]

This will internally redirect

  • www/player/testuser

to

  • www/player/?user=testuser
Comments