Forum Moderators: phranque
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.example.com/$1 [R=301,L]
Jim
GET /index.html HTTP/1.1
or
PROPFIND /widgets.html HTTP/1.0
By checking the request header as originally sent by the browser, we avoid doing this redirect as a result of DirectoryIndex internally rewriting a client request for the "correct" URL-path "/" to the "correct" filepath "/index.html", which would then result in another invocation of the rewrite rule, another DirectoryIndex rewrite, another rule invocation, etc. -- an 'infinite' loop.
In case it isn't obvious from the description above, Apache runs and re-runs the URL-manipulation and access-checking directives in .htaccess until no more internal rewrites are invoked as a result. Therefore, you should view .htaccess as repeatedly "calling itself" until all URLs are finally resolved to a file that exists.
Note that the [L] flag on a RewriteRule only stops mod_rewrite processing for the current pass through the mod_rewrite code. It does not force an exit from the URL-to-filename translation phase of the API to the content-handling API phase; This exit only takes place after Apache detects that no rewrites of any kind were invoked in the previously-completed pass, and that the result does not violate any access restrictions or point to a file that does not exist.
Jim
[edited by: jdMorgan at 7:50 pm (utc) on Nov. 17, 2006]
You can always test with a "nonsense" original URL like "outdox.php", request that URL from your server, and make sure it redirects to the proper URL. In this way, you won't interfere with the operation of your site, and can gain some confidence that it will work. Having reassured yourself, you can then change the URL pattern to "index\.php" and re-test.
Be sure to replace both instances of the URL pattern, and escape the literal periods as shown.
Jim