大网数据广告活动
网站运营与故障问答

What does this htaccess file do in this configuration?

· 52CE 我爱测

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 accomp…

问题原文

原帖链接 · 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 R flag, this will result in a temporary (302) redirect. Also, the absence of the L flag 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 RewriteRule substitution 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 (RewriteCond directives) mentioned above are added automatically by cPanel when SSL certs are renewed.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-05-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。