重定向到 https 时忽略 htaccess 中的特定文件

Ignore specific file in htaccess when redirecting to https

我尝试了很多组合并浏览了这个网站的例子,但 none 我尝试似乎有效,

我在我的客户站点上存储了一个电子邮件图像,默认情况下所有页面都通过 https 重定向,但这会导致发送 html 电子邮件时出现问题,其中图像存储在服务器上,我有一个允许我忽略给定文件夹的部分,这样它们就不会被推送 index.php 给我一个可以测试和做其他事情的区域,但即使是这些也是通过 https 发送的,

有没有办法忽略 htaccess 中的单个文件或目录以阻止它通过 https 发送?

这就是我现在所处的位置,我花了一个小时试图解决这个问题,所以请提供任何帮助

RewriteEngine on
#This is the directory I wish to be ignored:
RewriteCond %{REQUEST_URI} !^(.*/)?email/image/\.png$ [NC]
#Dont send these requests to index.php:
RewriteRule ^(ajax|test)($|/) - [L]
RewriteBase /
RewriteRule ^m/([^/\.]+)/?$ index.php?module= 
RewriteRule ^a/([^/\.]+)/?$ index.php?action= 
RewriteRule ^m/([^/\.]+)/([^/\.]+)/?$ index.php?module=&page= [L]
#ErrorDocument 404 /not_found.php

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*)$ https://example.com/ [R=301,L]

在此先感谢您提供的任何帮助或指点

首先,您需要所有重定向都发生在之前 您的路由规则。然后,您可以简单地在重定向到 HTTPS 的规则中添加一个条件:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^(.*/)?email/image/.+\.png$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*)$ https://example.com/ [R=301,L]

# Dont send these requests to index.php:
RewriteRule ^(ajax|test)($|/) - [L]

RewriteRule ^m/([^/\.]+)/?$ index.php?module= 
RewriteRule ^a/([^/\.]+)/?$ index.php?action= 
RewriteRule ^m/([^/\.]+)/([^/\.]+)/?$ index.php?module=&page= [L]
#ErrorDocument 404 /not_found.php

请注意,重写条件 适用于紧随其后的规则。因此,您必须通过将条件放在规则之前来专门将条件与特定规则匹配。

此外,您的电子邮件图片正则表达式似乎有问题。它只匹配这样的东西:/email/image/.png(例如没有文件名)。