rev*_*ezp 6 apache .htaccess mod-rewrite lets-encrypt
这是我目前的/ frontend/web的htaccess配置
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME} [R,L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
Run Code Online (Sandbox Code Playgroud)
我想插入这个:
RewriteCond %{REQUEST_URI} !^.well-known/acme-challenge/$
Run Code Online (Sandbox Code Playgroud)
要么
RewriteCond %{REQUEST_URI} ! /\.well-known|^\.well-known
Run Code Online (Sandbox Code Playgroud)
以上
RewriteRule ^.*$ https://%{SERVER_NAME} [R,L]
Run Code Online (Sandbox Code Playgroud)
创建letsecnrypt证书,但这些都不起作用.
Letsencrypt命令创建证书(debug coz Centos6):
./letsencrypt-auto --debug certonly --webroot -w /var/www/html/example.com/frontend/web/ --email example@gmail.com --domains example.com
Run Code Online (Sandbox Code Playgroud)
letsencrypt错误:
The following errors were reported by the server:
Domain: example.com
Type: unauthorized
Detail: Invalid response from
http://example.com/.well-known/acme-challenge/%acme%
Run Code Online (Sandbox Code Playgroud)
上面的链接引导我访问站点协议的HTTPS版本.如果我删除重定向到https,我会收到成功收到证书的消息.结论:.well-known继续发送到https,我的设置不起作用,我做错了什么?
我最终得到了这个配置,就像 cakephp 2 的魅力一样:
将其放在位于 webroot 和 app 文件夹上方的 .htaccess 文件中,与您的应用程序位于同一文件夹中
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^.well-known/ - [L,NC]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
只需更换底部 2 行以适合您的系统。
只需.well-known
从HTTPS重定向中排除,否则它将保留位置并且是永久的:
RewriteRule ^(?!\.well-known(?:$|/)).* https://%{SERVER_NAME}/$0 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
编辑:执行此操作而无需更改任何规则的最干净的方法是,在所有其他规则之前添加一条单独的规则,以有效地禁止对该目录进行重写,如下所示:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^\.well-known/.+ - [END]
Run Code Online (Sandbox Code Playgroud)
文件存在检查是可选的,并且省略它意味着您的服务器的默认错误响应将显示,而不是任何自定义错误页面。
归档时间: |
|
查看次数: |
13019 次 |
最近记录: |