# www to non-www generic
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
上面的示例不能用作旁观者,因为%1引用了最后一个RewriteCond,而不是我们用regexp过滤主机的第一个。
答案 0 :(得分:0)
使用变量
修复了通用www到非www的问题# www to non-www (fixed to work with CPANEL - AutoSSL)
SetEnvIf Host "^www\.(.*)$" my_domain=$1
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://%{ENV:my_domain}/$1 [R=301,L]
要绕过这个问题使用变量,它不漂亮但是有效!