当尝试将非www重定向到www时,err_too_many_redirects

时间:2018-01-05 18:41:18

标签: linux apache redirect apache2 apache2.4

内部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

0 个答案:

没有答案