Using mod rewrite to change url with username variable

How to change the following client url

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

      

to the server url

domain.com/profile.php?user_id=100

      

with username in php variable?

I know I need to edit the htaccess file with RewriteCond and RewriteRule, but I'm still not clear ...

How does Twitter manage their page URLs?

+1


a source to share


2 answers


Try the following rule:

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

      



This will rewrite requests /profile/

foobar

for /profile.php?user_name=

foobar

. Note that you can simply rewrite the username. Then your script will have to look for the user id.

+5


a source


Checkout RewriteMap .



0


a source







All Articles