-1

My site has subdirectories that include index.html files.

www.domain.com/.htaccess 
www.domain.com/index.html
www.domain.com/otherstuff/index.html

I have the following in the .htaccess file to run some php code on my main index page, but I know it also affects the index.html files in my subdirectories. How do I write it so it applies only to www.domain.com/index.html?

<Files index.html>
AddHandler x-httpd-php5-cgi .html
</Files>

I found this: Precise targeting of the Filesmatch directive

But I'm not interested in using an alternative method like redirecting because it doesn't answer the question. I want to know if it's possible to do it this way and if it is, how? If it's not actually possible, then I'll know that for future reference and will always use an alternative.

Thanks!

Community
  • 1
  • 1
user1418023
  • 335
  • 1
  • 3
  • 9
  • 1
    Just as you found out in the post your referenced you can't add a sub directory to the `` directive. It does not support a path. So you will either need to use that `alternative` or don't do it. Why are you against using another way that the **web server** supports? Apache gives you alternatives on purpose because every directive may not be suitable for all situations. You need to use what works. You might try `Location` directive but that is only in apache config. – Panama Jack Jan 30 '15 at 21:30
  • Thanks! I'm not against using an alternative. Typically when I ask how to do something on here, instead of getting an answer to that question, I get asked why I don't do it another way instead because it's "preferred". I wanted to make it clear that I wanted to know if it **can** be done in this way, not just be told to do something else without having that question answered. – user1418023 Jan 31 '15 at 16:51

1 Answers1

4

See the RemoveHandler docs:

The RemoveHandler directive removes any handler associations for files with the given extensions. This allows .htaccess files in subdirectories to undo any associations inherited from parent directories or the server config files.

So in the "otherstuff" directory, add another htaccess file that says:

<Files index.html>
RemoveHandler  .html
</Files>
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • This is the answer I was looking for, thank you so much! From what I understood on apache sites, it _seemed_ that if I wanted to use the directive as I have it, I'd have to create another htaccess in the subdirectories I want excluded to negate it, but I wasn't able to find any clear confirmation of that, only answers saying to use redirects, not use the .html extension, etc. Thanks for verifying this for me! – user1418023 Jan 31 '15 at 16:59