Reputation: 395
I want to create a dynamic url such that when I log in from my website my username will be shown on the url. For example, say I log in with:
with my username myname. The url should become
http://example-website.com/myname
but actually the web page is loginsuccess.php with an alias of myname which is my username
How can I do this?
Upvotes: 1
Views: 2890
Reputation: 9415
Quick Tips:
For a thorough explanation, see Facebook Like Custom Profile URL PHP.
Upvotes: 1
Reputation: 4042
This is actually pretty easy with .htaccess
and RewriteEngine. In the example below I'll be using some really simple (.*)
regex, which is just a wildcard so that everything will be accepted (a-zA-z0-9
).
/username
prefixed with profile
RewriteEngine on
RewriteRule ^profile/(.*) user_profile.php?username=$1
ErrorDocument 404 /pathtofile/404.html
Result: http://www.example-website.com/profile/john-smith
Working with just username
, this option will require some sort of Routing
class.
RewriteEngine on
RewriteRule ^(.*) user_profile.php?username=$1
ErrorDocument 404 /pathtofile/404.html
Result: http://www.example-website.com/john-smith
Using RewriteEngine with Suffix auth
RewriteEngine on
RewriteRule ^(.*)/auth auth_user.php?username=$1&q=auth
ErrorDocument 404 /pathtofile/404.html
Result: http://www.example-website.com/john-smith/auth
Upvotes: 5