URL缩短器如何处理域后的代码? [英] How does URL shorteners process the code after the domain?

查看:286
本文介绍了URL缩短器如何处理域后的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建URL缩短服务。大多数URL缩短程序服务都在域之后使用代码。例如, http://bit.ly/duSk8wK ,则duSk8wK就是代码。

.htaccess文件中需要什么代码才能使服务器读取路径部分 duSk8wK并在数据库中查询,而不是转到文件夹名称/ duSk8wK?

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?

推荐答案

在Htaccess中,您可以像这样进行重写:

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

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

然后在您的 redirect.php 中,只需使用 $ _ GET [ code]

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

这篇关于URL缩短器如何处理域后的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆