.htaccess Htaccess重定向到https,ads.txt除外

.htaccess Htaccess重定向到https,ads.txt除外,.htaccess,.htaccess,我想将我网站上的所有流量重定向到HTTPS,ads.txt文件除外。注意,它是一个文件,例如domain.com/ads.txt,而不是一个子文件夹,例如domain.com/all-files-in-here/ 我尝试了以下方法: RewriteEngine On RewriteCond %{REQUEST_URI} !/ads.txt RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R

我想将我网站上的所有流量重定向到HTTPS,ads.txt文件除外。注意,它是一个文件,例如domain.com/ads.txt,而不是一个子文件夹,例如domain.com/all-files-in-here/

我尝试了以下方法:

RewriteEngine On
RewriteCond %{REQUEST_URI} !/ads.txt
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
根据目前的测试工具,这不起作用

有人能告诉我我做错了什么吗

问候


詹姆斯

我知道这是一篇老文章,但我找不到一个可以接受的答案来回答谷歌Adsense的要求

使ads.txt文件可以通过HTTP和HTTPS访问

这对我有用

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/ads\.txt
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
当协议为HTTP时,您希望将每个url转换为HTTPS,但/ads.txt除外

当协议是HTTPS时,您不需要转换任何url

这提供了在HTTP和HTTPS上加载ads.txt所需的结果

干杯

Greg J

可能重复的