设置了一堆短/友好的URL重定向 [英] Setting up a bunch of short/friendly redirect URLs
问题描述
我需要安装数百个按照这个格式的短重定向的URL:
I need to setup hundreds of short redirect URLs which follow this format:
http://mysite.com/shorturl
这将重定向到
http://mysite.com/index.php?id=N
,其中N是对应于该快捷方式的ID。
http://mysite.com/index.php?id=N
, where N is the ID corresponding to that shortcut.
什么是做到这一点的最好办法..我应该写为各自分别为ModRewrite线,还是有更好的方式来做到这一点,它结合了数据库或文件存储列?
What's the best way to do this.. should I be writing a ModRewrite line for each individually, or is there a better way to do this that incorporates storing a column in the database or a file?
更新:澄清,所述标识N是在数据库中的ID。该SHORTURL是用于连接人到对应于该ID的页的小短语。
Update: to clarify, the id N is an ID in the database. The shorturl is a small phrase used for linking people to the page corresponding to that ID.
推荐答案
有一个原因,你不想做这样的事情使得
Is there a reason why you didn't want to do something like making
http://mysite.com/shorturl
重定向到
http://mysite.com/index.php?id=shorturl
和的index.php
可以查找正确的 ID
从数据库中的 SHORTURL
和做正确的事情。
And index.php
can look up the correct id
in the database from the shorturl
and do the right thing.
显然,要做到这一点,所有你需要在你的.htaccess一行:
Obviously, to do this, all you'd need is one line in your .htaccess:
RewriteRule ^([A-z,0-9,_,-]+)/?$ index.php?id=$1 [PT]
这篇关于设置了一堆短/友好的URL重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!