apache2.4 mod_rewrite排除特定的别名directroy / uri

我的一个虚拟主机上有以下设置:

...<VirtualHost *:80> ServerName cloud.domain.de ServerAdmin [email protected] ServerSignature Off Alias "/.well-known/acme-challenge" "/var/www/domain.de/vh-www/htdocs/public/.well-known/acme-challenge" <Directory "/var/www/domain.de/vh-www/htdocs/public/.well-known/acme-challenge"> Require all granted ForceType 'text/plain' </Directory> <ifmodule mod_rewrite.c> RewriteEngine On RewriteCond %(REQUEST_URI) !/\.well\-known/acme\-challenge/?.* RewriteCond %{HTTPS} off # RewriteRule ^\.well-known/acme-challenge/([A-Za-z0-9-]+)/?$ - [L] RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </ifmodule>... 

我想要实现的是,当url http://cloud.domain.de/.well-known/acme-challenge/被访问时,mod_rewrite不会重写URL。

我已经尝试了不同的方法,其中之一是上面提到的RewriteRule,但似乎没有任何工作:服务器每次都将其重写为https。

当我禁用重写testing的目的,我可以访问别名的URL就好了…

如何实现特定的URL不被重写?

像那样 :

 <ifmodule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/ RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </ifmodule> 

如果URI匹配start with /.well-known/acme-challenge/则请求不会被redirect

恕我直言,更短,更强大:

 RewriteCond %{REQUEST_URI} ^\.well\-known RewriteRule - [L] 

你可能想要添加/ acme-challenge /最终,但是如果你想用任意文件debugging它,比如./well-known/test,这个解决scheme效果更好

它实际上做了什么:看起来请求是否以.well-known开头,在这种情况下什么都不做(意思是 – ),并使其成为最后一个规则[L]

@mark“更短,更强大”变体的正确版本:

 RewriteCond %{REQUEST_URI} ^/\.well\-known RewriteRule . - [L]