2

i have already look for this How to create user profiles with PHP and MySQL and this profile username in URL instead of user ID and the others as well. but it is still not working for me. My current url when the user view his/her profile is like this http://localhost/sn/profile.php?id=1 now what i want for the url is to be like this http://localhost/sn/myusername i know this is maybe a duplicate but still any answer didn't work for me so far :( any help please? Thanks in advance.

This is what i have tried in my .htaccess

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)/$ http://localhost/sn/profile.php?id=$1
2
  • Where is located your htaccess ? In your sn directory or in document root directory ? Commented Feb 8, 2014 at 17:58
  • it is located inside the sn folder together with my index.php and profile.php Commented Feb 8, 2014 at 18:00

1 Answer 1

1

Your htaccess code should be as follow:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ profile.php?id=$1 [L]

Note that you have to change logic in profile.php to get user by username (and not by ID anymore)

Sign up to request clarification or add additional context in comments.

2 Comments

what do you mean by that sir?
An example: you want to reach http://localhost/sn/Pengun which is internally redirected to profile.php?id=Pengun. Before, your php page was receiving ID but now it is username

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.