如何删除 url [.htaccess] 中的 'index' 字样?

How to remove the word 'index' in the url [.htaccess]?

目前,我正在使用下面的代码删除我的网址中的 'index' 这个词 - 然而,问题是它允许两个版本:一个没有 [the word] 和一个带有 [the word] - 因此,我已经引用了没有(在 HTML 中)的那个 - 但用户仍然可以键入带有单词的那个。

如何从索引页中完全删除 'index' 一词:http://example.com/index[.html] 转到 http://example.com/index 但实际上应该转到 http//:example.com

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/index$ / [R=301]
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/  [R=301]

您可以使用:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index(?:\.html)?$ / [L,R=301,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/index$ / [R=301,L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$  [R=301,L]