Jump to content

.PHP or .HTML


joePHP

Recommended Posts

Hi,

 

I always thought that in order for the server to execute PHP code, you need to save the file as a PHP extension (.php) However, today I opened an existing sites index.html file and there is PHP code in it and it's getting executed properly. I was wondering if it's and option I could set in the ini.php file? or it's the server that is doing it?

 

Thanks,

Joe

Link to comment
https://forums.phpfreaks.com/topic/140879-php-or-html/
Share on other sites

How did you open this file? Did you do it through your browser (like, view source)?  If it's executing properly, and you can see the code from your browser, then it's not php.  As revraz mentioned, you can set your server to treat any file extension as anything you want.  But if you set a .html file to parse php, it still gets parsed on the server, just like a normal php file.  Only the results would be sent to your browser.

Link to comment
https://forums.phpfreaks.com/topic/140879-php-or-html/#findComment-737380
Share on other sites

Why not use the apache rewrite mod. Just simply make all html extensions redirect to php extensions without the user knowing it. So place the following in a file name '.htaccess' (nothing before the dot and without the quotes).

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

That is a very simple .htaccess file and believe me they can get complex when you want each php file to have $_GET[] variables. And another method which wikipedia uses is editing the apache httpd.conf file for simular rewrite rules.

 

From those 2 methods I recommend the .htaccess as you can't wreck the server no matter what you do with the .htaccess file unlike the httpd.conf file.

Link to comment
https://forums.phpfreaks.com/topic/140879-php-or-html/#findComment-737412
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.