内部virtuahost apache conf文件
sudo nano /etc/apache2/sites-available/000-default.conf
我试图将这些代码放在apache conf文件中
ServerName example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]
我也试过了,
< If "%{HTTP_HOST} != 'YOUR-DOMAIN.com'">
Redirect "/" "http://www.YOUR-DOMAIN.com/"
</If>
也做了这个
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
# real server configuration
</VirtualHost>
我还检查了官方的apache https://httpd.apache.org/docs/2.4/rewrite/remapping.html#canonicalhost