配置apache2 vhost

时间:2014-08-29 22:58:56

标签: apache ssl vhosts

我下面有以下vhost,我的目标是:

  • 将所有访问权限重定向到https(确定)
  • 配置我的ssl证书(确定)
  • 从网址
  • 中删除www

我仍然无法配置我的虚拟主机删除www并强制网址(使用301)到没有www的网址

<VirtualHost *:80>
    RewriteEngine on
    ReWriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
</VirtualHost>

<VirtualHost *:443>

    SSLEngine On
    SSLCertificateFile /usr/local/ssl/api_site_com.crt
    SSLCertificateKeyFile /usr/local/ssl/myserver.key
    SSLCACertificateFile /usr/local/ssl/api.site.com.cer

    ServerName api.site.com
    ServerAlias www.api.site.com

    DocumentRoot "/var/www/api.site.com/public"

    <Directory "/var/www/api.site.com/public">
        Options Includes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我使用这两行删除'www':

RewriteCond %{HTTP_HOST}   !^example\.com [NC]
RewriteRule ^/(.*)         http://example.com/$1 [R=301,L]