Mod-Rewrite
apache2.4 mod_rewrite 排除特定別名directroy/uri
我在我的一個虛擬主機上進行了以下設置:
...<VirtualHost *:80> ServerName cloud.domain.de ServerAdmin webmaster@domain.de 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 時 mod_rewrite 不會重寫 URL
http://cloud.domain.de/.well-known/acme-challenge/
。我已經嘗試了不同的方法,其中一種是上面註釋掉的 RewriteRule,但似乎沒有任何效果:伺服器每次都將其重寫為 https。
當我出於測試目的禁用重寫時,我可以很好地訪問別名 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/
,則不會重定向請求
@mark“更短更健壯”變體的正確版本:
RewriteCond %{REQUEST_URI} ^/\.well\-known RewriteRule . - [L]