1

How do I change the following client-side URL

domain.com/profile/jung
domain.com/jung (preferable)

to a server-side URL of

domain.com/profile.php?user_id=100

with the username in a php variable?

I know I need to edit my htaccess file with a RewriteCond and RewriteRule but it's still not clear to me...

How does Twitter manage their userpage URLs?

2 Answers 2

6

Try this rule:

RewriteRule ^profile/([^/]+)$ profile.php?user_name=$1

This will rewrite requests of /profile/foobar to /profile.php?user_name=foobar. Note that you just can rewrite the user name. You script will then have to look up the user ID if necessary.

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

3 Comments

Thanks, that worked! Is there any easy way to remove profile/ from the url? so that domain.com/jung would work as well? Alternatively, if I renamed profile.php to p.php, and changed the rewriterule to ^p/, would that affect all pages that started with the letter p?
Yes it could be removed. But you should ask yourself, if that’s necessary/useful. See stackoverflow.com/questions/780311/…
Excellent, thanks for that! Just what I was looking for. Also some things I hadn't even thought about.
1

Checkout the RewriteMap function.

Comments

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.