views:

44

answers:

3

Hi!

I have a htaccess problem.

My directory structure look like this:

/
HEADER.html
README.html
/stackoverflow/
/stackoverflow/.htaccess

.htaccess

ServerSignature Off
Options +Indexes
HeaderName /HEADER.html
IndexIgnore HEADER.html
ReadmeName /README.html
IndexIgnore /README.html
IndexOptions +FancyIndexing
AddCharset UTF-8 .txt
IndexIgnore *.xml
IndexIgnore *.php

My primary directory is /stackoverflow/, when I navigate to this directory via browser I have included HEADER.html and README.html on every site/directories under /stackoverflow/, this works fine.

I added some php code to my HEADER.html (which is in the root directory / ), I am trying to add to htaccess:

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

This not working, I think because the HEADER.html is in the root.

If I try add the AddType... to the /.htaccess (and not to the /stackoverflow/.htaccess) it is overwriting my /stackoverflow/.htaccess rules. Why? How I can add AddType rule to my /stackoverflow/.htaccess to Apache parse html file as php file?

+1  A: 

Your PHP parser will ignore a file of .html as it is designed to. .html should be rendered not processed, if you want to add additional logic to your header file you'll have to convert it to .phtml or .php. You could also create a new header file which then just includes the html.

About the question regarding the .htaccess override that's how apache mod_rewrite works. It's a hierarchal system and will load the first one it comes across starting from / moving towards the requested file.

Matt S
A: 
HeaderName /HEADER.php  
AddType text/html .php  
<Files "*.php">  
  AddHandler application/x-httpd-php .php  
</Files> 
Peter
A: 

An .htaccess file affects the directory it resides in and any sub directories. It can't do anything to directories above it in the tree. Check this out the htaccess docs for more details.

So, if you want to keep the .html extension, you would have to do the "AddType application/x-httpd-php .html .php .htm" at the root level "/.htaccess". Or, as Matt S suggest change the extension to something that gets processed as PHP.

anotherAlan