ForceType producing 500 Error on Apache 1.3

awells

Member
Mar 18, 2006
20
0
151
I am trying to setup a clean URL navigation, but I am having some trouble with internal server errors. I am basically trying to force the php type on a file called 'content', so I can have files such as www.mysite.com/content/blah/344. Anyways, this is what I was told to add to the .htaccess file:

Code:
<FilesMatch "^content$">
    ForceType application/x-httpd-php
</FilesMatch>
and this is the content file in the same directory:

Code:
<?php
	header('Content-type: text/html');
	echo 'It works!!';
?>
I want it to work on my main server, but it doesn't. My main server is running cPanel with php4 and Apache 1.3. This technique does work on my home webserver running php5 and Apache2, and it does work on my shared hosting account running php4 and Apache 1.3. When I get the internal server error, I look in the error log and see that the error says "Premature end of script headers." If I look at my suExec log, it says the script doesn't have executable permissions.

Any ideas? Thanks.
 

rustelekom

Well-Known Member
PartnerNOC
Nov 13, 2003
290
0
166
moscow
I think you just not enable all options in AllowOverride apache directives. (httpd.conf)
 

awells

Member
Mar 18, 2006
20
0
151
Ok, I just tried that. I changed 'AllowOverride All' in the <Directory /> directive, but still have the same error.
 

rustelekom

Well-Known Member
PartnerNOC
Nov 13, 2003
290
0
166
moscow
Possible mistakes
1) May be you enable AllowOverride in incorrect place
2) Your php run as cgi

You may check your /usr/local/apache/logs/error_log

you should find here more detailed information about problem.
 

awells

Member
Mar 18, 2006
20
0
151
Basically what I did was find every occurrence of AllowOverride in the file and change the options to All.

About the logs, the Apache error log says "Premature end of script headers", and the suExec log says "File has no execute permissions", but the file does have execute permissions. PHP files don't have to have executing permissions anyway - or so I thought.
 

rustelekom

Well-Known Member
PartnerNOC
Nov 13, 2003
290
0
166
moscow
If i am not wrong ForceType do not work under php as cgi (i.e. phpsuexec enabled). But i am not sure, we have similar problem very long time ago. Also try may be not a application/x-httpd-php but just for example text/html. There is may be some problem exist with apache handlers.
 

awells

Member
Mar 18, 2006
20
0
151
Well that's interesting. It works when I change the ForceType to text/html. So does that mean that it will not be able to force the php type?

Well, if I can't do it in the .htaccess file, I do have root access son this server, so could I just add the type in the conf file?
 

rustelekom

Well-Known Member
PartnerNOC
Nov 13, 2003
290
0
166
moscow
no, most likely just your "application/x-httpd-php" is not correct. Usually that means php runned as module not as binary. for binary you should use something like

AddType application/x-httpd-php .php .php3 .php4 .phtml
AddHandler x-httpd-php .php .php3 .php4 .phtml
 

awells

Member
Mar 18, 2006
20
0
151
Well, here is what I found in my httpd.conf file:
Code:
    #
    # AddHandler allows you to map certain file extensions to "handlers",
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action command (see below)
    #
    # If you want to use server side includes, or CGI outside
    # ScriptAliased directories, uncomment the following lines.
    #
    # To use CGI scripts:
    #
AddHandler application/x-httpd-php .php .php4 .php3
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .php3
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .phtml
AddHandler cgi-script .cgi .pl
AddType text/html .shtml
AddType application/x-tar .tgz
AddType text/vnd.wap.wml .wml
AddType image/vnd.wap.wbmp .wbmp
AddType text/vnd.wap.wmlscript .wmls
AddType application/vnd.wap.wmlc .wmlc
AddType application/vnd.wap.wmlscriptc .wmlsc
 

rustelekom

Well-Known Member
PartnerNOC
Nov 13, 2003
290
0
166
moscow
Yes, it's definately reason why your ForceType construction do not work with php.

May be something like:

AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi
ForceType php-cgi

in your .htaccess will help you... In aove example you use own apache handlers. Of course php patch should be corrected to your server files location

may be this directives can help you instead:

AddType application/x-httpd-php .php .phtml
 

awells

Member
Mar 18, 2006
20
0
151
I just tried that real quick with no luck.

I did recently learn something though. I rebuilt Apache w/o PHP suEXEC Support, and it does work, but I can't have that disabled because I can't have my mail scripts running as nobody. At least I know the culprit though.
 

rustelekom

Well-Known Member
PartnerNOC
Nov 13, 2003
290
0
166
moscow
i am not sure, but may be under suphp ForceType will work.
 

rustelekom

Well-Known Member
PartnerNOC
Nov 13, 2003
290
0
166
moscow
I think no. It shouldn't help.
 

awells

Member
Mar 18, 2006
20
0
151
Hello, I know it's been over a month since this thread was posted to, but I did find a solution to the problem. I found a quick any easy way to use Apache's mod_rewrite method and it works great. It's probably the more proper way to form clean URLs than the ForceType method I was talking about anyway.

Thanks for all your tips and advise!
 

jols

Well-Known Member
Mar 13, 2004
1,107
3
168
Care to share?

I am having the exact same issue, using php5 so far with no luck.

Whats your mod_rewrite method? How exactly do you implement it? In an .htaccess file?

Thanks very much.
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
I am having the exact same issue, using php5 so far with no luck.
Has nothing to do with being PHP5 ....

The issue at hand really is whether PHP is being run as a module or CGI.

When PHP is run as a CGI as is the case with phpSuExec or SuPHP then trying
to parse additional extensions as PHP by a simple "AddType" or similiar is
not going to be sufficient because PHP is not being handled by Apache.

In a similiar fashion, php_flag and php_admin commands won't work either
when PHP is setup as a CGI vs a loadable Apache module.

When PHP is run as a module then you do have the ability to use standard
"AddType" commands to add extensions, HTACCESS overrides, etc but at
a tremendous cost to security that comes with it.

There are ways to accomplish the same goel with PHP running as a CGI but
the configuration is going to be quite different and you need to learn the
differences between configuring CGI and module based PHP.
 

lijeeshsd

Active Member
Apr 22, 2005
33
0
156
ForceType will not work with phpsuexec. So use SetHandler, it will work for sure.

SetHandler application/x-httpd-php