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

.htaccess 重定向到https时忽略htaccess中的特定文件,.htaccess,mod-rewrite,redirect,https,.htaccess,Mod Rewrite,Redirect,Https,我尝试了很多组合,并在这个网站上查找了一些例子,但我尝试的组合似乎都不起作用 我有一个电子邮件图像存储在我的客户网站上,默认情况下,所有页面都通过https重定向,但这会导致在发送html电子邮件时出现问题,该图像存储在服务器上,我有一个部分,允许我忽略给定的文件夹,这样它们就不会通过index.php推送给我一个可以测试和做其他事情的区域,但即使是通过https发送 有没有一种方法可以忽略htaccess中的单个文件或阻止通过https发送的目录 这就是我目前所处的位置,我已经花了一个小时试图

我尝试了很多组合,并在这个网站上查找了一些例子,但我尝试的组合似乎都不起作用

我有一个电子邮件图像存储在我的客户网站上,默认情况下,所有页面都通过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=$1 
RewriteRule ^a/([^/\.]+)/?$ index.php?action=$1 
RewriteRule ^m/([^/\.]+)/([^/\.]+)/?$ index.php?module=$1&page=$2 [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/$1 [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/$1 [R=301,L]

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

RewriteRule ^m/([^/\.]+)/?$ index.php?module=$1 
RewriteRule ^a/([^/\.]+)/?$ index.php?action=$1 
RewriteRule ^m/([^/\.]+)/([^/\.]+)/?$ index.php?module=$1&page=$2 [L]
#ErrorDocument 404 /not_found.php
请注意,重写条件仅适用于紧跟其后的规则。因此,您必须通过将条件放在规则的前面,将条件与特定规则进行特定的匹配


另外,看起来你的电子邮件图像正则表达式可能不可靠。它只匹配这样的内容:
/email/image/.png
(例如,没有文件名)。

你是明星!,谢谢你,这工作做得很好,我似乎把它写错了,主要是因为它是这样写的,我试图在事实发生后插入忽略,但很高兴知道我做错了什么!哦,还有正则表达式,我试图对目录进行通配符