Cruachan
Cruachan

Reputation: 15971

Apache rewrite rule forces download

I'm trying to port a PHP site developed by another coder (who is no longer around) and I'm having a problem with the Apache Rewrite rules which are prompting a file download on the target server. I'm sure this is a simple problem, but I'm having some difficulty Googling an answer. I'm running on a (dedicated) Ubuntu Server with a standard installation of Apache and PHP5 and porting from shared a shared server where everything runs fine. No site files have been altered during the port.

The .htaccess file contains this code (only)

# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
Options -Indexes FollowSymlinks


RewriteEngine on
RewriteRule ^html/(.*)     /index.php?init=site\/$1\/$2\/$3\/$4\/$5\/$6\/$7\/$8\/$9

RewriteRule ^mykart$         /index.php?admin=true
RewriteRule ^mykart/$       /index.php?admin=true
RewriteRule ^mykart/(.*)$   /index.php?init=admin\/$1\/$2\/$3\/$4\/$5\/$6\/$7\/$8\/$9&admin=true


When I try to open the file http://www.mysite.com/html/#home the browser attempts to download the (index.php) file instead of displaying it, with the message

"You have chosen to Open [dialog shows blank space here]

which is a: application/x-httpd-php from.... "

I guess I must have missed something in either the PHP or Apache configuration, but what?

EDIT: To clarify, the server is running Apache2 and has several, functioning, PHP sites on it. Furthermore if I delete the .htaccess file and run a simple phpinfo display page everything runs fine, so it's not the execution of PHP per see.

Upvotes: 2

Views: 5410

Answers (3)

ivetame
ivetame

Reputation: 233

I had a similar issue. Browser attempted to download links from php website, instead of loading them.

It wasn't Php interpreter issue for me, it turned out to be misplaced .htaccess file. However, I didn't realized that disabling the htaccess file solved the issue for hours, due to browser cache.

So, don't forget to clear your browser caches! And restart Apache.

Upvotes: 0

Gumbo
Gumbo

Reputation: 655219

I suppose that the MIME type application/x-httpd-php5 is not valid. I’ve tried it on my local machine and it caused the same behavior.

Have you tried application/x-httpd-php instead?

Upvotes: 3

karim79
karim79

Reputation: 342635

Looks like an Apache config issue, of course I could be wrong. Have you checked httpd.conf for the following lines:

# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php

AddType text/html       php

Upvotes: 0

Related Questions