URL缩短器如何处理域后的代码?

编程入门 行业动态 更新时间:2024-10-16 22:23:08
本文介绍了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缩短器如何处理域后的代码?

本文发布于:2023-11-28 21:20:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何处理   代码   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!