Jump to content

Rookie question for php to html


joomwookie

Recommended Posts

Hi,

 

Just doing the basics here - using php includes inside my html files.  Everything there is working 'ok' and here is an include format that i'm using.

 

 <?php include ("mainnav.php");?>

 

I'm saving my files as .html files do the fact i have several html files already on the site and their indexed.  So, I'm trying to convince the server to parse the html file properly with php inside it.

 

I've tried the .htaccess file by adding this:

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

 

So far, my browsers(FF and IE8) are trying to open the web pages as script pages via download.

 

What am i doing wrong?

 

Thanks for any assistance.

 

Ryan

 

Link to comment
Share on other sites

Try this. Put this in your HTACCESS document:

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

 

Clear caches of ALL browsers, make sure you restart each one of them after clearing the cache, and it should work.

 

If it doesn't, What does the downloaded script contain? Your code or is it blank? Try running phpinfo() for any problematic settings.

Link to comment
Share on other sites

Essentially the idea is correct, but the concept backwards. You save the files as php, so the server knows how to handle them correctly, and tell .htaccess to serve the php file as if it were an html file.

You should look into using .htaccess for rewrite rules and not adding file types.

 

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

 

I think it should be more like

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

 

Alternatively you can go with the rewrite concept I mentioned and get html files to parse like php files. And just get the best of both worlds  ;)

RewriteEngine on 
RewriteRule ^(.*)\.html $1\.php

 

 

Link to comment
Share on other sites

@ monkeytooth - you're right on with what i'm trying to accomplish.  Serving PHP files as HTML files is exactly what i want to have happen.  What about testing on server side?  Do i just load up a test.php file and then try typing in test.html to see if it will serve file?  I like the rewrite idea as well.  Probably would eliminate the server trying to guess what i'm trying to accomplish.

 

Ryan.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.