Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有不同域名称的Apache虚拟主机SSL_Apache_Apache2_Virtualhost - Fatal编程技术网

具有不同域名称的Apache虚拟主机SSL

具有不同域名称的Apache虚拟主机SSL,apache,apache2,virtualhost,Apache,Apache2,Virtualhost,我有一个在VPS上运行的web应用程序和两个域名,比如说mywebsite.fr和mywebsite.com所有的域名(www.mywebsite.fr//mywebsite.fr//www.mywebsite.com//mywebsite.com)都指向Apache运行的服务器的IP地址(记录)已为这些域生成SSL证书 我是Apache的初学者我的目标是强制重定向到https://mywebsite.com/requested_route无论初始入口点是什么 我没有碰。我没有接触。我尝试了几次

我有一个在VPS上运行的web应用程序和两个域名,比如说mywebsite.fr和mywebsite.com

所有的域名(www.mywebsite.fr//mywebsite.fr//www.mywebsite.com//mywebsite.com)都指向Apache运行的服务器的IP地址(记录)

已为这些域生成SSL证书

我是Apache的初学者我的目标是强制重定向到https://mywebsite.com/requested_route无论初始入口点是什么

我没有碰。我没有接触。我尝试了几次apache conf,这一次接近预期结果:

<VirtualHost *:80>
        ServerName  mywebsite.com
        DocumentRoot /var/www/mywebsite/public
        <IfModule mod_rewrite.c>
                Options -MultiViews
                RewriteEngine On
                RewriteCond %{HTTP_HOST} !^mywebsite\.com$ [NC]
                RewriteRule ^ https://mywebsite.com%{REQUEST_URI} [R=301,L]
        </IfModule>
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin myemail@gmail.com
        ServerName  mywebsite.com
        DocumentRoot /var/www/mywebsite/public
        <Directory /var/www/mywebsite/public>
                AllowOverride None
                Order Allow,Deny
                Allow from All

                <IfModule mod_rewrite.c>
                        Options -MultiViews
                        RewriteEngine On
                        RewriteCond %{REQUEST_FILENAME} !-f
                        RewriteRule ^(.*)$ index.php [QSA,L]
                </IfModule>
        </Directory>

        # (Optional) Disable the RewriteEngine for the bundles asset directories
        <Directory /var/www/mywebsite/public/bundles>
                <IfModule mod_rewrite.c>
                        RewriteEngine Off
                </IfModule>
        </Directory>

        ErrorLog /var/log/apache2/mywebsite_error.log
        CustomLog /var/log/apache2/mywebsite_access.log combined
        SSLCertificateFile /etc/letsencrypt/live/mywebsite.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/mywebsite.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

服务器名mywebsite.com
DocumentRoot/var/www/mywebsite/public
选项-多视图
重新启动发动机
重写cond%{HTTP_HOST}^mywebsite\.com$[NC]
重写规则^https://mywebsite.com%{REQUEST_URI}[R=301,L]
服务器管理员myemail@gmail.com
服务器名mywebsite.com
DocumentRoot/var/www/mywebsite/public
不允许超限
命令允许,拒绝
通融
选项-多视图
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$index.php[QSA,L]
#(可选)禁用捆绑包资产目录的重写引擎
发动机熄火
ErrorLog/var/log/apache2/mywebsite\u error.log
CustomLog/var/log/apache2/mywebsite\u access.log组合
SSLCertificateFile/etc/letsencrypt/live/mywebsite.com/fullchain.pem
SSLCertificateKeyFile/etc/letsencrypt/live/mywebsite.com/privkey.pem
Include/etc/letsencrypt/options-ssl-apache.conf
我对此配置有以下结果:
- http://www.mywebsite.com -> https://mywebsbite.com ->好的
- http://www.mywebsite.fr -> https://mywebsbite.com ->好的
- http://mywebsite.com -> https://mywebsbite.com ->好的
- http://mywebsite.fr -> https://mywebsbite.com ->好的
- https://www.mywebsite.com -> https://mywebsbite.com ->好的
- https://www.mywebsite.fr -> https://mywebsite.fr ->不正常
- https://mywebsite.fr -> https://mywebsite.fr ->不正常
- https://mywebsite.com -> https://mywebsite.com ->正常(输入=期望结果)

我试图在443上重写.fr以转到.com,但我遇到了太多重定向错误或ssl错误

我应该更改什么以将用户重定向到https://mywebsite.com/any_route 如果他来自带https的.fr


感谢您的帮助

如果我理解,您希望将来自其他域和子域的每个请求重定向到

要做到这一点,请尝试此操作(在任何apache conf文件中,不要使用
RewriteEngine On
两次,除非您将其关闭)

需要明确的是,第一个重写条件检查主机是否为mywebsite.com

第二个重写条件检查HTTPS是否打开

如果其中任何一个条件为真,则重写规则将网站重定向到url类似的域

总配置如下所示:

<VirtualHost *:80>
        ServerName  mywebsite.com
        DocumentRoot /var/www/mywebsite/public
        <IfModule mod_rewrite.c>
                Options -MultiViews
                RewriteEngine On
                RewriteCond %{HTTP_HOST} !^mywebsite\.com$ [OR]
                RewriteCond %{HTTPS} !=on
                RewriteRule ^(.*)$ https://mywebsite\.com/$1 [R=301,L]
        </IfModule>
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin myemail@gmail.com
        ServerName  mywebsite.com
        DocumentRoot /var/www/mywebsite/public
        <Directory /var/www/mywebsite/public>
                AllowOverride None
                Order Allow,Deny
                Allow from All

                <IfModule mod_rewrite.c>
                        Options -MultiViews
                        RewriteEngine On
                        RewriteCond %{REQUEST_FILENAME} !-f
                        RewriteRule ^(.*)$ index.php [QSA,L]
                        RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR]
                        RewriteCond %{HTTPS} !=on
                        RewriteRule ^(.*)$ https://mywebsite\.com/$1 [R=301,L]
                </IfModule>
        </Directory>

        # (Optional) Disable the RewriteEngine for the bundles asset directories
        <Directory /var/www/mywebsite/public/bundles>
                <IfModule mod_rewrite.c>
                        RewriteEngine Off
                </IfModule>
        </Directory>

        ErrorLog /var/log/apache2/mywebsite_error.log
        CustomLog /var/log/apache2/mywebsite_access.log combined
        SSLCertificateFile /etc/letsencrypt/live/mywebsite.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/mywebsite.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

服务器名mywebsite.com
DocumentRoot/var/www/mywebsite/public
选项-多视图
重新启动发动机
重写cond%{HTTP_HOST}^mywebsite\.com$[或]
重写cond%{HTTPS}=在…上
重写规则^(.*)$https://mywebsite\.com/$1[R=301,L]
服务器管理员myemail@gmail.com
服务器名mywebsite.com
DocumentRoot/var/www/mywebsite/public
不允许超限
命令允许,拒绝
通融
选项-多视图
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)$index.php[QSA,L]
RewriteCond%{HTTP_HOST}^mywebsite\.com$[或]
重写cond%{HTTPS}=在…上
重写规则^(.*)$https://mywebsite\.com/$1[R=301,L]
#(可选)禁用捆绑包资产目录的重写引擎
发动机熄火
ErrorLog/var/log/apache2/mywebsite\u error.log
CustomLog/var/log/apache2/mywebsite\u access.log组合
SSLCertificateFile/etc/letsencrypt/live/mywebsite.com/fullchain.pem
SSLCertificateKeyFile/etc/letsencrypt/live/mywebsite.com/privkey.pem
Include/etc/letsencrypt/options-ssl-apache.conf

(可能将“我的网站”一词替换为您的网站名称)

这是否回答了您的问题?谢谢,但希望避免htaccess,并使用Vhost conf专门解决这个问题。谢谢语法建议。使用您的配置,由于“太多重定向”陷入无限循环,浏览器将停止。如果我删除您在443 Vhost中添加的重写行,我基本上回到了问题中提到的点。http ar中端口80上的请求很好,但443中带有.fr的端口没有重定向。请清除浏览器缓存,然后重试。现在应该可以了,尽管我迟到了,但我输入了一个错误。这对我帮助很大。谢谢虽然我不确定这次行动。
<VirtualHost *:80>
        ServerName  mywebsite.com
        DocumentRoot /var/www/mywebsite/public
        <IfModule mod_rewrite.c>
                Options -MultiViews
                RewriteEngine On
                RewriteCond %{HTTP_HOST} !^mywebsite\.com$ [OR]
                RewriteCond %{HTTPS} !=on
                RewriteRule ^(.*)$ https://mywebsite\.com/$1 [R=301,L]
        </IfModule>
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin myemail@gmail.com
        ServerName  mywebsite.com
        DocumentRoot /var/www/mywebsite/public
        <Directory /var/www/mywebsite/public>
                AllowOverride None
                Order Allow,Deny
                Allow from All

                <IfModule mod_rewrite.c>
                        Options -MultiViews
                        RewriteEngine On
                        RewriteCond %{REQUEST_FILENAME} !-f
                        RewriteRule ^(.*)$ index.php [QSA,L]
                        RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR]
                        RewriteCond %{HTTPS} !=on
                        RewriteRule ^(.*)$ https://mywebsite\.com/$1 [R=301,L]
                </IfModule>
        </Directory>

        # (Optional) Disable the RewriteEngine for the bundles asset directories
        <Directory /var/www/mywebsite/public/bundles>
                <IfModule mod_rewrite.c>
                        RewriteEngine Off
                </IfModule>
        </Directory>

        ErrorLog /var/log/apache2/mywebsite_error.log
        CustomLog /var/log/apache2/mywebsite_access.log combined
        SSLCertificateFile /etc/letsencrypt/live/mywebsite.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/mywebsite.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>