htaccess url重写(数据库访问)?
我有一个带有以下参数的网页。
http://www.somesite.com/community_details.php ?comm_id=233®ion_id=2&city_id=40
我希望将其更改为这个
http://www.somesite.com/virginia/fairfax/some_community/
如何致电db 返回地区、城市、社区以在 .htaccess 中进行 url 重写?
I have a web page with the following parameters.
http://www.somesite.com/community_details.php?comm_id=233®ion_id=2&city_id=40
I would like it changed to this
http://www.somesite.com/virginia/fairfax/some_community/
How do I call db to return region, city, community for a url rewrite in .htaccess?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它不是特别有效,但是您可以使用 RewriteMap 来使用一个外部 txt/dbm/程序,让 mod_rewrite 根据结果进行查找和重写。
从community_details.php脚本捕获的查询字符串将被传递到其stdin上的指定外部脚本,并且该脚本通过其stdout回复重写的url。
请注意,该脚本在 Apache 首次启动时启动一次,然后基本上以守护进程模式运行,为每次执行的重写与 Apache 进行通信。由于 PHP 不太适合编写守护程序,因此您可能想用其他语言来编写此程序。
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.
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.
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.
我认为; 如果您
的链接是 http://www.somesite.com/virginia/fairfax/ some_community/
您可以使用 htacces 将其更改为 http://www.somesite.com/community_details.php?comm_code =samo_community®ion_code=virginia&city_code=fairfax
并采取数据库中要在 php 中使用的代码 id。
I think; you can't
If your link is http://www.somesite.com/virginia/fairfax/some_community/
you could change it with htacces as http://www.somesite.com/community_details.php?comm_code=samo_community®ion_code=virginia&city_code=fairfax
and take id of codes from database to use in php.
阅读本文是一个好的开始:
http://httpd.apache.org/docs/current/mod/mod_rewrite .html#rewritemap
您为您的模式创建一个正则表达式,然后编写一个外部 Perl/PHP 脚本来实现对 MySQL 表的哈希查找并将其返回到 Apache。
Reading this is a good start:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritemap
You create a regex for your pattern, then write an external Perl/PHP whatever script that implements a hash lookup against a MySQL table and returns it to Apache.
嗯,这很简单。
只需将所有虚拟请求路由到 php scritp 即可查询数据库。
并且您将在 $_GET['request'] 中请求路径。
使用爆炸将其拆分并从数据库获取参数。
Well, it's quite easy.
just route ALL virtual requests to php scritp which will query a database.
and you will have requested path in $_GET['request'].
split it up using explode and get your parameters from db.
你不能。
您可以做的是让community_details.php 进行数据库查找,然后调用die(header("Location: blahblahblah"));。但是,您必须使用 .htaccess 和其他所有内容来处理该内容,因此根本不这样做可能会更容易 - 取决于此类 URL 对您来说有多重要。
You can't.
What you can do is have
community_details.php
do the database lookup, then calldie(header("Location: blahblahblah"));
. But then you would have to process that back using .htaccess and everything else, so it might be easier to just not do that at all - depends on how important such URLs are to you.