设置了一堆短/友好的URL重定向

编程入门 行业动态 更新时间:2024-10-14 12:24:32
本文介绍了设置了一堆短/友好的URL重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要安装数百个按照这个格式的短重定向的URL:

I need to setup hundreds of short redirect URLs which follow this format:

mysite/shorturl

这将重定向到

mysite/index.php?id=N ,其中N是对应于该快捷方式的ID。

mysite/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

mysite/shorturl

重定向到

mysite/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重定向

本文发布于:2023-11-12 19:57:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582391.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   友好   URL

发布评论

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

>www.elefans.com

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