Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
978 views
in Technique[技术] by (71.8m points)

apache - ForceType/htaccess file extension question - extensionless files?

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>

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).

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 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.

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?)

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...