本文介绍了URL缩短器如何处理域后的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建URL缩短服务。大多数URL缩短程序服务都在域之后使用代码。例如, 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, 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缩短器如何处理域后的代码?
发布评论