code works on index.php, but not index.html

VAisforlovers

Senior member
Jun 24, 2009
260
0
71
It's not my code but I installed it on my website. I'm assuming that the code was intended to be used off index.php homepages so it works there. But when I try to use it off index.html, it doesn't work even though the link (http://www.yourhomepage.com/user/x) that triggers the code exists on both index.php and index.html. What I'm saying is that they're both nearly identical except one homepage is .php and the other is .html.

Anyone know if there's an easy fix within the code that would make this work? I'm just trying to determine if there's some modification that I can make in the code to make .html work too.
 

beginner99

Diamond Member
Jun 2, 2009
5,315
1,759
136
if a file has a html ending it is by default not processed by php and hence no php code is executed.

AFAIK you can also have html files be processed by php (Apache setting) but IMHO makes no sense. just name it index.php.
 

VAisforlovers

Senior member
Jun 24, 2009
260
0
71
This is what my index.php file looks like
Code:
<?php

/**
 * @file
 * The PHP page that serves all page requests on a Drupal installation.
 *
 * The routines here dispatch control to the appropriate handler, which then
 * prints the appropriate page.
 *
 * All Drupal code is released under the GNU General Public License.
 * See COPYRIGHT.txt and LICENSE.txt.
 */

/**
 * Root directory of Drupal installation.
 */
define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();


The index.html file is a typical html webpage. What is the best way to get my index.html to replicate what's above? I want to keep everything that the .html currently has but make the installed code to work.

Would modifying the .htaccess file do the trick?
I will add this line:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

so this would make PHP handle the html webpage without having to rename it to .php
 
Last edited:

KB

Diamond Member
Nov 8, 1999
5,406
389
126
Like beginner99 says "why"? Keep the code in index.php, set the default document for the website to be index.php so it loads if not specified.

You can make php handle any extension, but lets say you want to have a plain html document with no php code, do you really want php to parse and process it?
 

xalos

Senior member
May 31, 2002
292
0
76
You can just copy the html portion of your current index.html and place it below the php portion of the index.php file and you can have the same html and have the php code execute.

Does your host support php or have it enabled on your account?
 
Last edited:

Red Squirrel

No Lifer
May 24, 2003
69,993
13,484
126
www.anyf.ca
I like to set htm and html to execute php code as well, to do this go in the apache config file (usually /etc/httpd/conf/httpd.conf) and look for a line that starts with AddType application/x-httpd-php and Simply add .htm and .html to it.

You can also look for DirectoryIndex and change the priority of the default page. Ex: add index.php, and just rename it back to .php.


If shared hosting you should be able to make a .htaccess file with these parameters in it.
 

tech7

Junior Member
Feb 22, 2013
7
0
0
By default PHP only executes files with the .php extension. If you really want to run .html files through the PHP interpreter then as others have said you can add the modification to a .htaccess (Apache only).