问题原文
原帖链接 · drtechno · CC BY-SA 4.0
I've never seen this configuration in .htaccess. This comes from my site that currently reset. I have no SSL certificate installed, but I remember seeing these names on previous certs though.
So does anyone know what this accomplishes?
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/www\.example\.com\/" [R=301,L]
社区高分解答
原帖链接 · MrWhite · CC BY-SA 4.0
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$I have no ssl certificate installed
Well, you probably do now!? These (type of) conditions are injected automatically by cPanel when it auto-renews the (usually FREE) security certs (eg. those provided by "Let's Encrypt"). This is to ensure that the validation file (required during installation) can be accessed.
Some (shared) web hosts now appear to enable these free SSL certs whether you explicitly requested them or not.
See my answer to a similar question over on ServerFault for more details:
https://serverfault.com/a/884922/49157
Aside:
RewriteCond %{HTTPS} on
You say you didn't have an SSL cert installed, however, you were attempting to perform an HTTPS to HTTP redirection (which would be pointless without an SSL cert, but also backward if you did).
RewriteRule ^/?$ "http\:\/\/www\.websitename\.com\/" [R=301,L]
This only redirects the single request for the document root - is that intentional? However, in your exemplified code, this looks like it would result in a redirect loop?!
UPDATE: Maybe you were after the bigger picture...?
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/www\.example\.com\/" [R=301,L]
There is nothing particularly strange here. These is just two incompetently written redirects, which will likely break your server (unless something has been lost in the exemplified code in your question):
The first is an HTTPS to HTTP redirect. Although you have to ask why? You would need to have an SSL cert installed in the first place to avoid browser warnings. And if you have an SSL cert installed then why not use the SSL cert? (But then, maybe your site isn't HTTPS-ready?) However, because of the lack of the
Rflag, this will result in a temporary (302) redirect. Also, the absence of theLflag will allow the rewrite engine to continue through the file.The second looks, at first, like a canonical non-www to www redirect (which, incidentally, looks as if it was generated by cPanel - the unnecessary abundance of backslash escapes in the
RewriteRulesubstitution is a telltale sign). However, the additional condition that checks against the canonical hostname will result in a redirect loop! It also only redirects the document root.The two other conditions (
RewriteConddirectives) mentioned above are added automatically by cPanel when SSL certs are renewed.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
