在不使用 mod_rewrite 的情况下运行没有扩展名的 PHP? [英] Running PHP without extension without using mod_rewrite?
问题描述
使用 Apache 2.2 和 PHP 5,在没有 .php
扩展名的情况下运行 PHP 的最佳方法是什么?例如,我有一个名为 app.php
的脚本,我喜欢将其调用为:
Using Apache 2.2 and PHP 5, what's the best way to run PHP without the .php
extension? For example, I have a script called app.php
and I like to invoke it as:
请注意,我仍然想保留文件的 .php
扩展名,并且我没有 mod_rewrite
.也不想使用 index.php
因为它需要太多目录.
Please notice that I still want to keep the .php
extension to the file and I don't have mod_rewrite
. Don't want use index.php
either because it requires too many directories.
我确实找到了一种方法,将它添加到我的 .htaccess
中,
I did find one way by adding this to my .htaccess
,
AddHandler server-parsed .php
SetHandler application/x-httpd-php
AddHandler application/x-httpd-php .php
使用这个页面运行速度会慢一些.我怀疑它会在每个 PHP 页面上调用 SSI.想知道是否有更好的方法来实现这一点.
The page runs a little slower by using this. I suspect it invokes SSI on every PHP page. Wonder if there are any better ways to accomplish this.
推荐答案
An alternative is to use content negotiation. Turn on multiviews:
Options +MultiViews
如果命名资源不存在,Apache 将搜索该文件,然后根据浏览器发送的媒体类型和内容编码要求进行排序.如果只有一个文件(您的 PHP 脚本),则 URL 将解析为该文件.
If a named resource doesn't exist, Apache will glob for the file, then sort based on the media type and content encoding requirements send by the browser. If there's only one file (your PHP script), then that's what the URL resolves to.
这篇关于在不使用 mod_rewrite 的情况下运行没有扩展名的 PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!