user3944364
user3944364

Reputation: 121

Vanity url don't work

.htaccess file

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} -f [or]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://examplesite.com/vanity.php?un=$1 [NC]

php file

if(isset($_GET['un'])){

$myusername = mysqli_real_escape_string($con,$_GET['un']);


$sql="SELECT * FROM users WHERE Username='".$myusername."'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) === 1){echo 'hey' . $myusername;}
}

I enter the url http://examplesite.com/john and I get http://examplesite/vanity.php?un=john with 'hey john' on page, *instead of url http://examplesite.com/john with 'hey john' on page

This is the tutorial, but I don't see where is the problem.

Upvotes: 0

Views: 177

Answers (1)

Panama Jack
Panama Jack

Reputation: 24468

That's not the way I would do my rules. Try this way.

Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /vanity.php?un=$1 [NC,L]

Upvotes: 1

Related Questions