PHP运行不带扩展名不使用mod_rewrite? [英] Running PHP without extension without using mod_rewrite?

查看:253
本文介绍了PHP运行不带扩展名不使用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

http://example.com/app <​​/A>

http://example.com/app

请注意,我仍然希望保持PHP扩展的文件,我没有mod_rewrite的。不想使用的index.php可能是因为它需要太多的目录。

Please notice that I still want 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

该网页运行使用该慢一点。我怀疑它会调用SSI每一个PHP页面上。不知道是否有什么更好的方法来做到这一点。

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将用于glob的文件,然后进行排序的基础上的介质类型和内容编码要求发送浏览器。如果只有一个文件(你的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.

这篇关于PHP运行不带扩展名不使用mod_rewrite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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