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