How to Dynamically Rewrite a URL like Facebook

前端 未结 4 364
滥情空心
滥情空心 2021-01-17 03:49

I\'ve written my site using PHP and unfortunately the Artist profiles are currently like this:

website.com/profiles.php?id=xxx

That way I can GET the id and

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 04:12

    Firstly, you need alter your artists table, adding a new column for define an alias for artists, like 'david-matthews-band', create an index unique to prevent confusions with homonym artists.

    You need edit your profile.php to find artists by alias, like website.com/profile.php?q=david-matthews-band

    Create a rewrite rule to transform website.com/profile/david-mattews-band to website.com/profile.php?q=david-matthews-band:

    RewriteEngine On
    RewriteRule ^profile/*  profile.php?q=$1
    

提交回复
热议问题