简体   繁体   English

Letsencrypt虚拟主机与Apache上的htaccess

[英]Letsencrypt virtual host vs htaccess on apache

I have a site that I was working to move to use the virtualhost configuration over an .htaccess. 我有一个网站正在迁移,以通过.htaccess使用virtualhost配置。 Figuring if I have the access I should. 确定是否有访问权限。

The rewrite I have was for php slim framework to remove index.php 我的重写是针对php slim框架,以删除index.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

When I made the changes of moving from .htaccess to the production server routes were failing. 当我进行从.htaccess到生产服务器的更改时,路由失败。 I realized that the rewrites were not being followed on the :80 virtualhost but rather what was specified in the :443 letsencrpyt virtualhost. 我意识到,不是在:80虚拟主机上进行重写,而是在:443 letsencrpyt虚拟主机中指定了重写。

In a pinch I just moved the above re-write into the letsencrpyt and voila working. 紧要关头,我只是将上面的重写内容移入了letsencrpyt和voila的工作中。

It seems that certbot uses the :80 port to create the :443 so I cannot remove that and just go with the generated one. 看来certbot使用:80端口创建:443,所以我无法删除它,只能使用生成的端口。 Right now I am just duplicating the logic between the two. 现在,我只是在两者之间复制逻辑。

Question I have at this point for this type of re-write should I just leave it in the .htaccess? 我现在有这种类型的重写的问题,我应该将其保留在.htaccess中吗? Or is there a way to update the ssl vhost with certbot when I make changes to the default port 80 one? 或者,当我对默认端口80进行更改时,是否可以使用certbot更新ssl vhost?

Considering your comments to the question I now see that your actual question is: 考虑到您对问题的评论,我现在看到您的实际问题是:

"How is it possible to share configuration directives between different hosts in an apache http server? " “如何在apache http服务器中的不同主机之间共享配置指令?”

This is easily possible using the Include statement: 使用Include语句很容易实现:

<VirtualHost *:80>
        # include the rules common for http and https
        Include sites-includes/shared-config.inc
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
        # include the rules common for http and https
        Include sites-includes/shared-config.inc
</VirtualHost>
</IfModule>

Using that you can now define common configuration directives in the file sites-includes/shared-config.inc (or wherever you want to place it). 使用它,您现在可以在文件sites-includes/shared-config.inc (或任何您要放置的位置)中定义通用配置指令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM