Custom urls - giving each user a url

前端 未结 3 1722
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 02:27

I am building a website and I would like to customize the users\' profile so their profile url shares their name. For example, the website domain would be www.example.com an

3条回答
  •  青春惊慌失措
    2020-12-12 03:05

    You are looking for a RewriteRule. I think the following should do:

    RewriteRule ^(.*)$ index.php?username=$1 [NC]
    

    This will convert the displayed url (www.example.com/myusername), to an url with a GET parameter for your index.php. This new url that you can use internally will look like this:

    www.example.com/index.php?username=myusername
    

    Update: Here is an extra clarification to answer the questions in your comment:

    The RewriteRule above does exactly what you are asking. The user can enter an url like www.example.com/username, which will be internally rewritten (without the user ever noticing it) to www.example.com/index.php?username=myusername. That way you can access the get variable ($_GET["username"]), without the user ever seeing it exists.

    Nice tutorials can be found here and here.

提交回复
热议问题