Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

php - htaccess url rewrite (db access)?

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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}

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...