htaccess的URL重写(数据库访问)? [英] htaccess url rewrite (db access)?

查看:55
本文介绍了htaccess的URL重写(数据库访问)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下参数的网页。

I have a web page with the following parameters.

http://www.somesite.com/community_details.php?comm_id=233&region_id=2&city_id=40

我希望将其更改为此

http://www.somesite.com/virginia/fairfax/some_community/

我如何将db称为返回区域,城市,社区以在.htaccess中重写url?

How do I call db to return region, city, community for a url rewrite in .htaccess?

推荐答案

这不是特别有效,但是您可以使用< a href = http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritemap rel = nofollow> RewriteMap 使用外部txt / dbm /程序让mod_rewrite执行查找并根据结果进行重写。

It's not particularly efficient, but you CAN use a RewriteMap to use an external txt/dbm/program to let mod_rewrite do lookups and rewrite based on the results.

RewriteMap pretty-community prg:/path/to/some/shell/script

RewriteRule community_details.php?(.*) ${pretty-community:$1}

从中捕获的查询字符串将在其stdin上将community_details.php脚本传递到指定的外部脚本,并且该脚本通过其stdout答复重写的URL。

The captured query string from the community_details.php script would be passed to the specified external script on its stdin, and the script replies with the rewritten url via its stdout.

请注意,脚本已启动Apache首次启动时,然后本质上以守护程序模式运行,在每次执行重写时均与Apache通信。由于PHP并不特别适合编写守护程序,因此您可能希望使用其他某种语言来编写此程序。

Note that the script is started ONCE when Apache first fires up, and then essentially runs in daemon mode, communicating with Apache for every rewrite performed. Since PHP isn't particularly suitable for writing daemons, you might want to do this program in some other language.

这篇关于htaccess的URL重写(数据库访问)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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