Reputation: 2139
I am trying to make a redirection service, which can redirect users to their profile page, based on a vanity url.
The vanity URL will be of the format - www.site.com/username
This will redirect them to a page profile_redirect.php, which will echo the username (The functionality is deeper, but this is all I need help with).
I tried several of the answers posted here, but I am unable to get this to work. At the moment, it does nothing and just gives me a page not found error. I am running this on wamp, and I have localhost's alias set to "proj", so I call "http://proj/username
", but this gives me page not found.
My current htaccess file (Relevant portion)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME} >""
RewriteRule ^([^\.]+)$ profile_redirect.php?user=$1 [L]
My current profile_redirect.php file
$getName=$_GET["user"];
echo $getName;
Upvotes: 1
Views: 352
Reputation: 785481
Have your rules like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)/?$ $1.php [L]
RewriteRule ^([^\.]+)/?$ profile_redirect.php?user=$1 [L,QSA]
Upvotes: 1