Forum Moderators: phranque
RewriteCond %{REQUEST_URI} ^/((?:\w+/)*)index\.html
RewriteRule index\.html$ https://example.com/%1 [R=301,NS,L]
Doing it this way saves having to evaluate conditions every single time, and saves making a capture that 99 times out of 100 will end up being thrown away unused. The [NS] flag prevents the rule from firing on internal subrequests, specifically the ones made by mod_dir, so it obviates the need for a Condition involving THE_REQUEST.
I tried this two waysCareful! If you redirect to a non-canonical form of your hostname, then when the internal request meets your canonicalization redirect, the whole thing including “index.html” will get externally redirected. Based on OP, the site uses the with-www form.
RewriteOptions IgnoreInherit
somewhere in your htaccess. (It can go anywhere, but immediately before the mod_rewrite section makes most sense.)
Yes. Bluehost has changed something. I have no idea what.
[edited by: not2easy at 3:08 am (utc) on Sep 18, 2023]
[edit reason] please use example.com for readability [/edit]
on the first line, is HTTP/ correctYes, because this isn't about http/https. Glance at your logs and you'll see that it always says HTTP/ followed by a number: currently 1.0 (only used by elderly robots), 1.1 or 2.0 (most humans now).
RewriteCond %{REQUEST_URI} ^/((?:\w+/)*)index\.html
RewriteRule index\.html$ https://example.com/%1 [R=301,NS,L]
The reasoning behind this version is that 99 requests out of 100 will not involve “index.xtn”--in fact, apart from malign robots, I don’t see it at all except on one older site that used to have visible URLs in “index.html”.* The act of capturing, in and of itself, creates a teeny bit of work for the server, so it makes sense to defer it for those times when the capture will actually be needed. Hence the Condition and the %1. Note the [NS] flag. This is crucial, because it prevents the rule from firing when "index.xtn" is an internal subrequest, generally from mod_dir.