Forum Moderators: coopster
My site structure is like this:
www.example.com/index.html
www.example.com/sub-directory/index.html
www.example.com/sub-directory/sub-sub-directory/index.html
The problem I am faced with is that I want to restrict the parsing to just the index.html in the root of my website and not the index.htmls in the subdirectories of my site.
I have the following line in my htaccess which is in the root of my site:
<Files index.html>
AddType application/x-httpd-php .html
</Files>
Is this gonna do the trick? Or is it going to parse all index.htmls in my site? If so, does anyone have the correct directive I can use?
Thanks
If you're only applying it to one file, can you do mod_rewrite? This might work better:
RewriteEngine On
RewriteRule ^(index.html*)$ /yourscript.php [L]
RewriteRule ^$ /yourscript.php
Some notes:
the * means "zero or more of the preceding character" so it will also work for requests for index.htm
The second rule means "begins and ends with nothing" so will manage requests for example.com/ in addition to example.com/index.html
If you want to pass parameters to the script,
index.html?id=1234
Do this:
RewriteRule ^(index.html*)$ /yourscript.php?%{QUERY_STRING} [L]
RewriteRule ^$ /yourscript.php?%{QUERY_STRING}
yourscript.php should receive id=>1234 in $_GET/$_REQUEST
Note I am not a mod_rewrite expert, there may be more accurate solutions, but I use these and they work without issues.
Anyway, If you only want to do the index.html script, you should use a RewriteRule like rocknbil suggested. I don't know if there's a way to limit the rules to ignore subdirectories. I couldn't find one from Google.
I just ran a test and the htaccess as I have it is also parsing the index.htmls in subdirectories as php.
Sorry, I may have confused you, and am not extremely familiar this THAT approach. What you're doing there is adding the directive to parse HTML as PHP, and as you discovered, this probably affects all directories under it. As mentioned, if you use the mod_rewrite directive, it will only affect the directories containing that .htaccess.
BTW, the code posted above is redundant and has several other issues. Both rules can be replaced by one, "?" should have been used instead of "*", and it is not necessary to 'handle' the query string, which will pass through unaffected if no "?" is used in the substitution:
# Rewrite requests for "/index.html", "/index.htm", and "/" to /yourscript.php
RewriteRule ^(index\.html?)?$ /yourscript.php [T=application/x-httpd-php,L]
Jim
As long as you have "index.php" in your list of index files in a DirectoryIndex directive (in your .htaccess file, or defined in the server config), the redirect to index.php to "/" should have no negative consequences for search.
My site is hosted on a shared server so I have no way of knowing if index.php is in the list of index files in the server config.
But this is default behaviour for a apache web server isn't it?