本文介绍了用lighttpd重写 - 如何删除文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用lighttpd的mod_rewrite来允许没有特定文件扩展名的请求。例如,我希望以下映射自动工作:
I would like to use lighttpd's mod_rewrite to allow requests without a specific file extension. For instance, I would like the following mappings to automatically work:
- 请求/ index将提供/index.php。
- / dir / file=>/ dir / file.php
- / dir / file?args=> / dir /file.php?args
这可以通过给定扩展的单个重写规则轻松完成(例如.php )?
Can this be easily done with a single rewrite rule for a given extension (e.g. ".php")?
推荐答案
Cassy和natbro得到的这几乎是正确的,但正如user102008评论的那样,这会错误地重写任何目录索引。 url.rewrite-一旦匹配任何以'/'结尾的东西似乎使它工作。
Cassy and natbro got this very nearly right, but as user102008 commented, this erroneously rewrites any directory index. Adding a url.rewrite-once matching anything ending with a '/' seems to make it work.
url.rewrite-once = ( "^(.*)/$" => "$1/" )
url.rewrite-if-not-file = ( "^([^?]*)(\?.*)?$" => "$1.php$2" )
这篇关于用lighttpd重写 - 如何删除文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!