ForceType指令/ htaccess文件扩展名的问题 - 无扩展名的文件? [英] ForceType/htaccess file extension question - extensionless files?

查看:725
本文介绍了ForceType指令/ htaccess文件扩展名的问题 - 无扩展名的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的.htaccess文件:

This is my .htaccess file:

<IfModule php4/5.c>
php_admin_flag Option
php_flag Option
php_admin_value Option
php_value Option
</IfModule>  
<Files .>
ForceType application/x-httpd-php
SetHandler application/x-httpd-php
</Files>

以上code以某种方式,但我不知道为什么,虽然...我预计500错误。我没事的。htaccess的,但主要是为了避免遮挡机器人/蜘蛛的事情等,而不是文件类型。该文件的顶部是为自定义的php.ini文件(我试图复制我自己的Apache服务器上,如果我不得不正确的php.ini文件无法访问,就像他们做网络托管公司的网站,只是为了在我的测试网站的真实感)。

The above code somehow works, but I'm not sure why though... I expected a 500 error. I'm OK at .htaccess, but mainly for things like blocking robots/spiders etc. rather than filetypes. The top of the file is meant for custom php.ini files (I was trying to replicate on my own Apache server as if I had no access to the proper php.ini file, like they do on web hosting companies' sites, just for added realism on my testing sites).

虽然我知道如何使用ForceType指令和SetHandler,我不知道如何使用它的扩展名的文件(例如,如果我有一个名为testing1文件,我可以运行它作为PHP)。

Although I understand how to use ForceType and SetHandler, I'm not sure how to use it for extensionless files (e.g. if I had a file called testing1, I could run it as php).

previously我就是这么做的:

Previously I did it this way:

<Files testing1>
ForceType application/x-httpd-php
SetHandler application/x-httpd-php
</Files>

却成了繁琐这样做是为了每一个扩展名的文件。

but it became tedious doing it for every single extensionless file.

基本上,我想要做的就是确保我必须通过ForceType指令/ SetHandler指令扩展名的文件,但是这可能吗? (而且是象征以上在我的第一个例子通配符之一,还是不?)

Basically, what I'm trying to do is to ensure that I have extensionless files via the ForceType/SetHandler directives, but is it possible? (and is the symbol above in my first example the wildcard one, or not?)

感谢

推荐答案

DefaultType的中的Apache 2.4已被删除。最好的选择是如下:

DefaultType has been removed in Apache 2.4. Your best option is the following:

<Files *>
    ForceType application/x-httpd-php
</Files>
<Files *\.*>
    ForceType None
</Files>

这将捕获的所有文件不带扩展名并处理它们,因为PHP。然后用扩展名的文件将被处理为正常。

This will catch all files without an extension and process them as PHP. Then all files with an extension will be processed as normal.

使用 mod_mime_magic模块是不是一个很好的选择,因为每个文件需要每次都进行检查。见href="http://httpd.apache.org/docs/current/mod/mod_mime_magic.html"> mod_mime_magic模块文档获取更多信息

Using mod_mime_magic is not a good choice as each file will need to be checked each time. See the mod_mime_magic docs for more info.

这篇关于ForceType指令/ htaccess文件扩展名的问题 - 无扩展名的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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