使用Apache2的http到https重定向不起作用

时间:2017-07-22 14:20:52

标签: ubuntu apache2

我目前正在使用Apache托管网站的AWS实例。我已经设置了我的SSL,我可以转到https://example.com就好了,但是当我转到http://example.com时,我没有被重定向。有了这个,我尝试了以下内容:

  • 在我的example.com.conf中我尝试过Redirect permenant / https blah blah
  • 也在.conf中使用了许多重写规则,声称'这将适用于任何配置'。我也启用了Apache2重写mod。
  • 我已经sudo a2ensite example.com.conf

这是我的.conf

<VirtualHost *:80>
    ServerName example.com
    ServerAlias example.com *.example.com
    Redirect permanent / https://example.com/
    #RewriteEngine On
    #RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
    ... all my site stuff
</IfModule>

我将非常感谢能够提供帮助的任何人。非常感谢你。

1 个答案:

答案 0 :(得分:0)

更改/etc/apache2/apache2.conf =&gt;全部更改所有AllowOverride

并确保/etc/apache2/sites-available/000.default.conf =&gt;验证您访问的目录的路径。

ServerAdmin webmaster@localhost
DocumentRoot /var/www/floder that you acess /public
<Directory /var/www/ninja/public>   
AllowOverride All
</Directory>