将所有请求redirect到除某些文件夹以外的域

我尝试将所有请求从一个域redirect到一个子域,除了/mypath和下面的所有东西。 例子:

 example.com -> sub.example.com example.com/somestuff -> sub.example.com 

但是example.com/my-path不应该被redirect。

这里是负责configuration的部分:

 RewriteCond %{HTTP_HOST} ^example.com$ RewriteCond %{REQUEST_URI} !^/my-path/ RewriteRule ^/?(.*)$ "http\:\/\/sub\.example\.com" [R=301,L] 

问题是我无法实现目标,我不知道这里有什么问题。 我试图find一个实现相同的目标,但没有运气的例子。

只有在input了URI /my-path/而不是/my-path时,才能匹配尾部斜线

使用

 RewriteCond %{HTTP_HOST} ^example.com$ RewriteCond %{REQUEST_URI} !^/my-path RewriteRule ^/?(.*)$ "http\:\/\/sub\.example\.com" [R=301,L] 

所以它会计算/my-path//my-path