ForceType, AddType and/or AddModule?
am 05.04.2008 23:58:01 von chadsspameateremail
I'm brand new to Apache and pretty confused. I hope my question is a
simple one. I'd really like to know the fundamental difference
between AddModule, AddType and ForceType. I have read the Apache
documentation located here:
http://httpd.apache.org/docs/2.0/mod/mod_mime.html
However it isn't clear for example why I should choose one over the
other for configuration. What's the difference? Perhaps I'm so new
to Apache that I just really don't get it.
On some webpages I see directives like:
AddType application/x-httpd-php .php
On others it is like this:
AddHandler php-script .php .htm .html
Still other pages where the suggestion is to use both of the above.
Which of these is right? I have also read on one page that AddType is
wrong and AddHandler is right but why? Not only that but I think
AddType is using the MIME type application/x-httpd-php which I don't
think is even a valid mime type according to iana who I believe is the
authority on MIME types:
http://www.iana.org/assignments/media-types/
I also ran across another page from someone who seemed very
knowledgable on the subject who suggested to use ForceType if I want a
certain named file without an extension to be handled as PHP:
ForceType application/x-httpd-php
I'd really like to know what the difference is here and why I should
pick one other the other? I'm not someone who does the whole "try it
and if it works great" I'd rather configure Apache right the first
time rather then configure it now and then find out later its not
configured properly and have to go and fix it. That is do it right
the first time...
I apologize for all the questions, maybe you can tell I'm
confused. :)
Chad.
Re: ForceType, AddType and/or AddModule?
am 06.04.2008 21:03:15 von Kees Nuyt
On Sat, 5 Apr 2008 14:58:01 -0700 (PDT),
chadsspameateremail@yahoo.com wrote:
>I'm brand new to Apache and pretty confused.
It is confusing, and the ducumentation is very compact.
>I hope my question is a simple one.
>I'd really like to know the fundamental difference
>between AddModule, AddType and ForceType. I have read the Apache
>documentation located here:
>http://httpd.apache.org/docs/2.0/mod/mod_mime.html
In short:
The AddModule directive no longer exists in Apache2.
(See: http://httpd.apache.org/docs/2.0/upgrading.html )
AddType maps an extension to a MIME type (in addition
to the Default mime type and the types listed in the
TypesConfig file, usually conf/mime.types .
The MIME type can be used in a few ways:
- to associate a request with a handler
- as content-type header in the response.
>However it isn't clear for example why I should choose one over the
>other for configuration. What's the difference? Perhaps I'm so new
>to Apache that I just really don't get it.
I'm not too sure about it myself.
>On some webpages I see directives like:
>AddType application/x-httpd-php .php
Usually that is sufficient. My guess is, at startup PHP
(php_module) will register itself with Apache httpd as
the handler for the MIME type application/x-httpd-php
>On others it is like this:
>AddHandler php-script .php .htm .html
I think you need to do that when you want all of those
those file types has to be handled by php as a CGI
handler (php-cgi.exe), not by the php5_module.
Usually you have something like
LoadModule php5_module "/apache/bin/php5apache2_2.dll"
and you don't want to use AddHandler php-script.
>Still other pages where the suggestion is to use both of the above.
Some people want to use php4 and php5 at the same time
in the same Apache webserver instance.
That can only be accomplished by using CGI (phpscript)
for one version and php_module for the other version.
>Which of these is right?
They are both right at different times ;)
>I have also read on one page that AddType is
>wrong and AddHandler is right but why? Not only that but I think
>AddType is using the MIME type application/x-httpd-php which I don't
>think is even a valid mime type according to iana who I believe is the
>authority on MIME types:
>http://www.iana.org/assignments/media-types/
AddHandler forces an extension to be handled by a
specific handler, overriding the MIME type.
So it is more direct.
>I also ran across another page from someone who seemed very
>knowledgable on the subject who suggested to use ForceType if I want a
>certain named file without an extension to be handled as PHP:
>
>
>ForceType application/x-httpd-php
>
This is a trick to start a PHP script called "download"
whenever the location starts with download (like in
http://www.domain.tld/download/some/path/and/filename.ext
) and have it handle the whole location (available in
PATH_INFO) instead of Apache searching for that
specific file.
So, the location becomes a "virtual path" and a
"virtual filename" and the download script decides what
to deliver.
The reasons to do that are in the original article:
http://richardlynch.blogspot.com/2006/06/php-downloads-conte nt-disposition.html
and it can also be used to add access control via php.
>I'd really like to know what the difference is here and
>why I should pick one other the other?
>I'm not someone who does the whole "try it
>and if it works great" I'd rather configure Apache right the first
>time rather then configure it now and then find out later its not
>configured properly and have to go and fix it. That is do it right
>the first time...
That's a good approach. On the other hand, both Apache
and PHP, as well as the way they interact, may change
over time. What is right today may be wrong next year.
>I apologize for all the questions, maybe you can tell I'm
>confused. :)
I hope this helped a bit.
>Chad.
--
( Kees
)
c[_] Checkuary, n.: The thirteenth month of the year. Begins New Year's Day and ends when a person stops absentmindedly writing the old year on his checks.
(Rich Hall, "Sniglets") (#518)