htaccess 从 https 中排除 sitemap.xml 和 robots.txt

htaccess exclude sitemap.xml and robots.txt from https

嗨堆栈溢出。

我被难住了,无法正确理解,我只想从 https 中排除根目录中的两个文件,robots.txt 和 sitemap.xml。站点的其余部分通过 https,没问题。我明白了:

# Forcing HTTPS
# RewriteCond %{SERVER_PORT} !^443$  
# RewriteCond %{REQUEST_URI} !^sitemap.xml$
# RewriteCond %{REQUEST_URI} !^robots.txt$
# RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [L]

这显然会导致重定向循环等。那么...对 htaccess 菜鸟有什么帮助吗?

试试这条规则:

RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$  
RewriteCond %{THE_REQUEST} !/(robots\.txt|sitemap\.xml)\s [NC]
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,NE,R=302]

在新浏览器中测试一下。