How does URL shorteners process the code after the

2019-03-07 08:38发布

问题:

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"].