Apache mod_rewrite重定向过多(最多一个重定向?)

Apache mod_rewrite重定向过多(最多一个重定向?),apache,.htaccess,redirect,mod-rewrite,subdomain,Apache,.htaccess,Redirect,Mod Rewrite,Subdomain,我希望使用我的htaccess文件最多有一个重定向。可能吗 我的htaccess文件: RewriteEngine On #remove index/index.html RewriteRule index\.html|index https://example.com/ [R=301,L] #redirect to non-wwww and https site RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\.(.*)

我希望使用我的htaccess文件最多有一个重定向。可能吗

我的htaccess文件:

RewriteEngine On
#remove index/index.html
RewriteRule index\.html|index https://example.com/ [R=301,L]

#redirect to non-wwww and https site
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.html [NC]
RewriteRule ^ /%1? [R=301,L]

#remove .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]
如果我输入例如
http://example.com/foo.html
http://example.com/index
然后我有两个重定向

如果我输入例如
http://example.com/
https://example.com/foo.html
那么我只有一个重定向

我想要的是:

  • 我最多需要一个重定向(参见最后两个示例)
  • 如果我导航到主页,那么我总是希望删除index/index.html
  • 所有http调用都应重定向到https调用
  • 使用www调用的所有URL都应在不使用www的情况下调用
  • 如果我导航到子页面(
    https://example.com/foo.html
    ),则仅应分别删除html。用户可以调用不带.html(
    https://example.com/foo

这可能吗?目前,有时会发生两次重定向。

请根据所显示的示例尝试以下内容。请确保在测试URL之前清除浏览器缓存

RewriteEngine ON
##Apply https and remove www together for all requests here.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [NE,L]

##Server files with backend .html files.
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.*)$ $1.html [L]

##Deal with home page .html stuff here.
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^(.*)$ index/index.html [L]

谢谢你的评论。但不幸的是,这并不奏效。当我输入
https://example.com
,我得到一个无限循环。当我输入
https://example.com/foo
我得到一个无限循环。当我输入
https://example.com/index
我得到了无限的重定向到
https://example.com/index
@Sud0,我已经在我的系统中测试了这些规则。在htaccess中,除了上述规则之外,还有其他规则吗?你能告诉我吗?是的,但没有进一步的重写规则。只有ServerSignature、AddDefaultCharset、缓存规则和压缩规则。