HTTP重定向不重定向

时间:2017-08-16 09:19:56

标签: apache http https ubuntu-server server-configuration

根据建议here,我在Apache配置文件中使用以下代码(在本例中为default-ssl.conf)

<VirtualHost *:80>
    ServerName name.domain.com
    Redirect / https://name.domain.com/
</VirtualHost>

我重新启动了Apache并且......没有。没有错误,没有重定向。 Http用作http,https用作https。我做错了什么?我的域名不是以&#34; www&#34;开头的。但我无法想象会有所作为。

1 个答案:

答案 0 :(得分:0)

不确定这是否有帮助,还有一段时间浏览器需要DNS缓存尝试清除它,在chrome中你可以转到chrome:// net-internals / #dns并清除它,或使用其他浏览器进行测试。

<VirtualHost *:80>
  DocumentRoot /home/webroot/example.com/htdocs

  ServerName example.com
  ServerAlias www.example.com

  <Directory /home/webroot/example.com/htdocs>
    FileETag MTime Size
    DirectoryIndex index.php index.html index.htm
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

  RewriteEngine on
  Redirect permanent / http://www.example.com/
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

  ErrorLog /home/webroot/example.com/logs/error_log
  CustomLog /home/webroot/example.com/logs/access_log combined
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot /home/webroot/example.com/htdocs

  ServerName www.example.com

  RewriteEngine on
  Redirect permanent / http://www.example.com/
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

  ErrorLog /home/webroot/example.com/logs/error_log
  CustomLog /home/webroot/example.com/logs/access_log combined
  RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>