How does URL shorteners process the code after the domain?

社会主义新天地 提交于 2019-12-03 01:28:23

问题


I'm trying to create a URL shortener service. Most URL shortener services have use a code following the domain. For example, http://bit.ly/duSk8wK, duSk8wK would be the code.

What code is needed in .htaccess file to make the server read the path part 'duSk8wK' and query in database, instead of going to the folder name /duSk8wK?


回答1:


In your Htaccess, you could make a rewriterule like this:

RewriteRule ^([^/.]*)$ redirect.php/?code=$1 [L]

Then in your redirect.php, you could simply get the code by using $_GET["code"].



来源:https://stackoverflow.com/questions/34855381/how-does-url-shorteners-process-the-code-after-the-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!