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

本文介绍了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
<Files .>
ForceType application/x-httpd-php
SetHandler application/x-httpd-php

上面的代码以某种方式工作,但我不知道为什么......我预计会出现 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).


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


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 *\.*>
    ForceType None

这将捕获所有没有扩展名的文件并将它们作为 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 不是一个好的选择,因为每次都需要检查每个文件.有关详细信息,请参阅 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屋!

登录 关闭
发送“验证码”获取 | 15天全站免登陆