当前位置: 动力学知识库 > 问答 > 编程问答 >

html - Create a unique URL like facebook

问题描述:

How exactly does one do something like create a unique URL.

Like how facebook does it facebook.com/mynamehere

One way would be to create multiple folders each time we have a new user..but that doesn't seem to be the best approach

网友答案:

You can try a program like Elgg if you are trying to build a social media site. Otherwise, a person's profile can be custom in a couple of ways. Most of them mentioned. You, as mentioned, can use .htaccess for rewrites. You can use an automated custom url plugin (this may help: How to generate a custom URL from a html input?). Similarly, you can use the previously mentioned Elgg for social media, and but also as a last resort can use your folder method, but only if absolutely required.

网友答案:

I think the question is: how is it done technically, so we don't need to have physical file for every valid URL?

The answer is URL rewriting. In case of Apache server, you want to enable mod_rewrite and configure it to translate particular URL pattern (like myfbclone.com/mynamehere to myfbclone.com/index.php?username=mynamehere). This way you need to have one script file that handles all the URLs accordingly.

Different servers have different means of rewriting URLs, like Nginx or IIS, so the exact way of configuration depends on your server, but the concept is usually the same.

分享给朋友:
您可能感兴趣的文章:
随机阅读: