短网址系统:如何重定向自定义网址? [英] Short URL system: How to redirect the Custom URLs?

查看:129
本文介绍了短网址系统:如何重定向自定义网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使一个TinyURL的类似服务,为我公司,至今看起来不错,但现在我有一个问题,我解决不了。

I'm trying to make a tinyurl-like service for my company, and so far looks good, but now I have a problem I can't solve.

可以说,我产生的URL是www.thecompanyiworkfor.com/shorturl/2jh62/。我的猜测是我必须使用一些脚本,可以说redirect.php,我在那里访问数据库,查找短网址,发现原来的,并重定向与头。

Lets say the URL I generate is "www.thecompanyiworkfor.com/shorturl/2jh62/". My guess is I have to use some script, lets say "redirect.php", where I access the databank, look for that short url, find the original one, and redirect with headers.

我的问题是,我怎么能作出这样的www.thecompanyiworkfor.com/shorturl/2jh62/打开redirect.php那我可以访问SHORTURL作为参数?我想我会做一些与htaccess的,但我真的不知道我该怎么办?

My question is, how can i make that "www.thecompanyiworkfor.com/shorturl/2jh62/" open "redirect.php" and that I can access the "shorturl" as a parameter? I thought I would have to do something with .htaccess, but I'm not really sure what should I do...

请帮助!

推荐答案

下面是我推荐的。

1)创建一个子域(s.thecompanyiworkfor.com)。这将是更容易管理,并避免与htaccess的冲突,因为该文件夹从主WWW文件夹分开。

1) Create a sub domain (s.thecompanyiworkfor.com). It will be easier to manager and you avoid conflict with .htaccess since this folder is separated from the main WWW folder.

例如:

s.thecompanyiworkfor.com => /home/thecompanyiworkfor.com/s_public_html/
www.thecompanyiworkfor.com => /home/thecompanyiworkfor.com/public_html/

2)使用这个的.htaccess中的 /home/thecompanyiworkfor.com/s_public_html /

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^index\.php
RewriteRule ^([a-z0-9\-]+)(\/?)$ index.php?code=$1 [L,NC,QSA]

然后在你的 /home/thecompanyiworkfor.com/s_public_html/index.php 您可以检查哪些code对应于哪个URL和重定向。如果没有找到,重定向到 www.thecompanyiworkfor.com

Then in your /home/thecompanyiworkfor.com/s_public_html/index.php you can check which code correspond to which URL and redirect. If not found, redirect to www.thecompanyiworkfor.com

这篇关于短网址系统:如何重定向自定义网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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