开发者

Apache .htaccess

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 +Fan开发者_如何学CcyIndexing
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?


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.


HeaderName /HEADER.php  
AddType text/html .php  
<Files "*.php">  
  AddHandler application/x-httpd-php .php  
</Files> 


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜