2

First, excuse my web-illiteracy. Trying to do something that is probably simple, but cant figure it out... I have a website that was originally created in straight HTML - awhile ago.

I want to start including some PHP script onto the pages. So, the only way I know to do this is to save the pages with the php extension (i.e. "something.php"). But, the problem with that, is that I have so many pages, and there are so many links I would have to fix. However, if I am correct, there are some other ways to do this...

Can I have the server treat the HTML pages as PHP? Or read the html extention as is if it is a php document? How would I go about doing this?

I see that people are claiming this question has already been asked. Most people suggest adding this to my htaccess file:

AddType application/x-httpd-php .htm .html

But when I do that, and go to a page on my site, my browser starts to download the file (so if I go to my homepage, my browser automatically starts to download index.html)


RESOLVED

I figured this out. It is on a GoDaddy server (who I hate). In order to get this to work, you need to add some information (and wait a little bit for it to take effect) ...

Options +ExecCGI 
AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php5-cgi .php .htm .html

I hate Godaddy. I've had this happen with other server issues - a simple solution wont work, and GoDaddy servers require "special" care.

1 Answers1

4

You can make your server parse HTML files as PHP, no need to rename all the files. You can do so the simplest way by adding this to your .htaccess file:

RemoveHandler .htm .html5
AddType application/x-httpd-php .htm .html 

or, depending on the server:

AddType application/x-httpd-php5 .htm .html

Note that this will turn on PHP for every HTML file you have, even if it has absolutely no PHP code inside.

Shomz
  • 36,161
  • 3
  • 52
  • 81
  • When I add those lines to my htaccess file, and go to my site, the browser starts to download the file (so, if I go to the homepage, it will download the index.htm file). – user3412194 Apr 05 '14 at 02:16
  • 1
    Is Apache's PHP module loaded? (have you ever seen a properly rendered PHP page on your server?) – Shomz Apr 05 '14 at 05:29
  • I created a php page with phpinfo. PHP Version 5.3.24 – user3412194 Apr 05 '14 at 12:36
  • And it renders properly, you see the info page? – Shomz Apr 05 '14 at 20:00
  • Yes, it gives me all the PHP info (version number at the top) – user3412194 Apr 06 '14 at 17:39
  • Got it fixed. Because its a GoDaddy server, it required some extra info (see my initial question, I added the solution above) ... – user3412194 Apr 07 '14 at 15:23
  • I see, sorry you went through all the trouble, but I'm glad you finally got it sorted. Though, I'm still a bit puzzled about why did the phpinfo page work in the first place. – Shomz Apr 07 '14 at 15:25