Reputation: 795
How do I modify ^(.*/)index\.html$
properly to match index.html with or without extension ?
example.com/index.html - match
example.com/index - match
example.com/indexx - ignore
if ($request_uri ~* "^(.*/)index\.html$") {
return 301 $1;
}
Upvotes: 0
Views: 227
Reputation: 22817
Wrapping \.html
into a capture group and making it optional ?
(match zero or one time) allows you to make the extension optional:
# your regex:
^(.*/)index\.html$
# change to:
^(.*/)index(\.html)?$
# ^ ^^
Upvotes: 2