joomwookie Posted April 2, 2010 Share Posted April 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/ Share on other sites More sharing options...
oni-kun Posted April 2, 2010 Share Posted April 2, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/#findComment-1035668 Share on other sites More sharing options...
monkeytooth Posted April 2, 2010 Share Posted April 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/#findComment-1035670 Share on other sites More sharing options...
oni-kun Posted April 2, 2010 Share Posted April 2, 2010 RewriteEngine on RewriteRule ^(.*)\.html $1\.php No, <FilesMatch "\.(htm|html|php)$"> SetHandler application/x-httpd-php </FilesMatch> Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/#findComment-1035674 Share on other sites More sharing options...
joomwookie Posted April 2, 2010 Author Share Posted April 2, 2010 @ 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. Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/#findComment-1035676 Share on other sites More sharing options...
joomwookie Posted April 2, 2010 Author Share Posted April 2, 2010 you want me to use that 2nd code set? Ryan. Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/#findComment-1035678 Share on other sites More sharing options...
joomwookie Posted April 2, 2010 Author Share Posted April 2, 2010 oni-kun - what are you saying? Is the 1st mentioned way not correct? Ryan Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/#findComment-1035679 Share on other sites More sharing options...
oni-kun Posted April 2, 2010 Share Posted April 2, 2010 Mod_rewrite should not handle what mod_mime is supposed to do. Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/#findComment-1035681 Share on other sites More sharing options...
joomwookie Posted April 2, 2010 Author Share Posted April 2, 2010 ok, so modrewrite worked like a charm, but your last method did not work oni. I loaded a php file to the server (index.php) - then i typed in index.html and the page was served. Seems right to me - would you agree? Ryan. Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/#findComment-1035685 Share on other sites More sharing options...
oni-kun Posted April 2, 2010 Share Posted April 2, 2010 All depends on how your server is set up, Adding a handler would show the master ini file was not set up properly with PHP, such as a stale upgrade. Quote Link to comment https://forums.phpfreaks.com/topic/197318-rookie-question-for-php-to-html/#findComment-1035689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.