Mod_rewrite澄清问题.仅用于动态网址? [英] Mod_rewrite clarification question. Only for dynamic urls?
问题描述
已要求我开发一个mod_rewrite进行更改
I've been asked to develop a mod_rewrite to change
http://www.example.com/health-and-fitness-tips/999/
进入
http://www.example.com/health-and-fitness-tips/how-do-I-lose-10kg-in-12-weeks/
其中999
是id
,How do I lose 10kg in 12 weeks
是title
.
这甚至是远程可行的吗?还是只为了更改类似内容而使用mod_rewrite
Is this even remotely possible or is mod_rewrite only for changing something like
http://localhost/siteengine/products.php?id=123
进入
http://localhost/products/123
???
推荐答案
我猜想答案是您正在寻找的答案,但是从技术上讲,您可以创建一个静态地图文件来将一组标题字符串重定向到id,并且不必执行外部prg
可执行文件:
i'm guessing the answer meder gave is the one you're looking for but technically you can create a static map file to redirect a set of title strings to ids and it doesn't have to execute an external prg
executable:
RewriteMap static-title-to-id txt:/tmp/title_to_id.txt
RewriteRule ^/health-and-fitness-tips/(.*)/ /health-and-fitness-tips/${static-title-to-id:$1}/ [L]
包含/tmp/title_to_id.txt
文件的内容,如下所示:
with the contents of the /tmp/title_to_id.txt
file something like this:
how-do-I-lose-10kg-in-12-weeks 999
some-other-title 988
and-another 983
这篇关于Mod_rewrite澄清问题.仅用于动态网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!