Apache Mod_Rewrite www 到非 www 不起作用

问题描述 投票:0回答:0

我正在尝试执行 Mod_Rewrite 并删除网址中的所有 www.。我所有的 SSL 证书都是非 www 的,我不想为 www 创建 SSL 证书。子域。我只是想重写和重定向。

<VirtualHost *:80>
 ServerAdmin webmaster@localhost
 DocumentRoot /var/www/html
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
 RewriteEngine on
 RewriteCond %{HTTPS} off
 RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
 RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
 RewriteRule ^ https://%1%{REQUEST_URI} [END,L,R=permanent]
</VirtualHost>
<Directory /var/www>
 Options Indexes FollowSymLinks
 AllowOverride All
 Require all granted
</Directory>

其次是

sudo systemctl restart apache2
,但经过测试,
www.
仍然持续存在。

apache mod-rewrite
© www.soinside.com 2019 - 2024. All rights reserved.