gpt4 book ai didi

apache2 www到非www重定向不起作用

转载 作者:行者123 更新时间:2023-12-04 22:39:04 25 4
gpt4 key购买 nike

在尝试了许多不同的组合以将我的 shopware6 安装重定向到具有 apache2 的服务器上之后,我无法使 www 到非 www 重定向工作。
这是我的conf文件:

<VirtualHost *:80>
ServerName vanparysbakery.emakers.be
ServerAlias www.vanparysbakery.emakers.be
RewriteCond %{HTTPS} off
RewriteEngine On
ServerSignature Off
</VirtualHost>
<VirtualHost *:443>
Protocols h2 h2c http/1.1
LoadModule ssl_module /usr/lib64/apache2-prefork/mod_ssl.so
DocumentRoot /var/www/bakery/public
ServerName vanparysbakery.emakers.be
ServerAlias www.vanparysbakery.emakers.be
<Directory /var/www/bakery/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!aNULL:!MD5:!ADH:!DH:!RC4
SSLHonorCipherOrder on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/vanparysbakery.emakers.be/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/vanparysbakery.emakers.be/privkey.pem
</VirtualHost>
以下是我尝试进行重定向的不同方法(在 conf 文件中的“RewriteEngine on”下方添加):
RewriteCond %{HTTP_HOST} ^www.vanparysbakery.emakers.be [NC]
RewriteRule ^(.*)$ http://vanparysbakery.emakers.be/$1 [L,R=301]
&&&&
RewriteCond %{SERVER_NAME} =www.vanparysbakery.emakers.be [OR]
RewriteCond %{SERVER_NAME} =vanparysbakery.emakers.be
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

在我的 shopware 文件夹的 .htaccess 文件中也试过这个:
RewriteEngine On
RewriteRule ^(.*) http://vanparysbakery.emakers.be/$1 [QSA,L,R=301]
&&&&
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
我究竟做错了什么?我对此学到了很多东西,我发现的所有解决方案都没有给出预期的结果。我怀疑 apache 配置会“阻止”这种重定向。
任何形式的帮助都会很棒:)
更新 (@MikeMoy 建议的我的 conf 文件的新内容):
<VirtualHost *:80>
ServerName vanparysbakery.emakers.be
ServerAlias www.vanparysbakery.emakers.be
RewriteEngine on
#Redirect 301 / http://vanparysbakery.emakers.be/
RewriteCond %{HTTP_HOST} www.vanparysbakery.emakers.be [NC]
RewriteRule ^/?(.) vanparysbakery.emakers.be/$1 [L,R,NE]
ServerSignature Off
</VirtualHost>
<VirtualHost *:443>
Protocols h2 h2c http/1.1
LoadModule ssl_module /usr/lib64/apache2-prefork/mod_ssl.so
DocumentRoot /var/www/bakery/public
ServerName vanparysbakery.emakers.be
ServerAlias www.vanparysbakery.emakers.be
<Directory /var/www/bakery/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} www.vanparysbakery.emakers.be [NC]
RewriteRule ^/?(.) https://vanparysbakery.emakers.be/$1 [L,R,NE]
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!aNULL:!MD5:!ADH:!DH:!RC4
SSLHonorCipherOrder on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/vanparysbakery.emakers.be/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/vanparysbakery.emakers.be/privkey.pem
</VirtualHost>
更新 2 :
我对另一个具有相同行为“covarmed.emakers.be”的网站尝试了相同的修复。在我执行这个命令之后: curl -I www.covarmed.emakers.be (我也用“covarmed.emakers.be”和“http://www.covarmed.emakers.be”试过这个)。每次的 react 都是一样的:
HTTP/1.1 302 Found
Date: Fri, 27 Aug 2021 09:42:09 GMT
Server: Apache/2.4.38 (Debian)
Location: https://covarmed.emakers.be//
Content-Type: text/html; charset=iso-8859-1
但在浏览器中,结果仍然相同,重定向不起作用。 CURL RESPONSE

最佳答案

像这样,然后重新启动服务器以加载新配置

<VirtualHost *:80>
RewriteRule ^(.*)$ https://vanparysbakery.emakers.be/$1 [R,L]
</VirtualHost>


<VirtualHost *:443>
RewriteCond %{HTTP_HOST} www.vanparysbakery.emakers.be [NC]
RewriteRule ^/?(.*) https://vanparysbakery.emakers.be/$1 [L,R,NE]
</VirtualHost>

关于apache2 www到非www重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68908443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com