In this code with mod_rewrite I can visit the profile of any user by typing his username after domain like example.com/john this will take us to john's profile. This works well however if I type any name which is not a username for existing user in my database like example.com/notauser I still get redirected to a empty profile page, though it has no profile pic or other info but all other buttons and links like followers, friends etc are still available. In such a case I want to redirected to login page or echo message user does not exist, but can't figure out how to do that.
profile.php
.htaccess file
profile.php
Code:
<?php if(!empty($_GET['username'])) { $username = $_GET['username']; } else if(!empty($_SESSION['username'])) { $username = $_SESSION['username']; } else { header("Location: login.php"); die(); } ?>
Code:
RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
Comment