vHost和SSL中的mod_rewrite

时间:2015-01-14 15:39:31

标签: php apache .htaccess mod-rewrite ssl

我正在搜索整个网络,但我找不到解决问题的方法。

我的服务器是使用apache2.2的debian 7.7。我有很多vhost和一个SSL证书。所有域都指向同一目录(/ var / www / www)。例如,我有以下域名:

  • www.domain.gv.at
  • www.domain.at
  • www.example.at
  • www.anotherexample.at

我会将所有.htaccess内容移动到他们的vhost中。

首先,我会将www.domain.gv.at www.domain.at domain.gv.at domain.at重定向到https。我的.htaccess文件看起来像这样:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.gv\.at [NC,OR]
RewriteCond %{HTTP_HOST} ^domain\.gv\.at [NC,OR]
RewriteCond %{HTTP_HOST} ^domain\.at [NC]
RewriteRule ^(.*)$ https://www.domain.at/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]

我也想要漂亮的网址(即https://www.domain.at/cool/page)所以我的.htaccess中有以下内容

RewriteRule ^/typo3$ - [L]
RewriteRule ^/typo3/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* /index.php

现在我试图在我的vHost配置中复制所有内容但没有成功。我的vHost(端口80)看起来像这样:

<VirtualHost *:80>
    ServerName www.domain.at
    ServerAlias domain.at domain.gv.at www.domain.gv.at

    DocumentRoot /var/www/www/
    ErrorLog /var/log/apache2/www.domain.at-error.log
    CustomLog /var/log/apache2/www.domain.at-access.log vhost_combined_ip

    <Directory /var/www/www>
      Options -Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all

      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^www\.domain\.gv\.at [NC,OR]
      RewriteCond %{HTTP_HOST} ^domain\.gv\.at [NC,OR]
      RewriteCond %{HTTP_HOST} ^domain\.at [NC]
      RewriteRule ^(.*)$ https://www.domain.at/$1 [R=301,L]

      RewriteCond %{HTTPS} !=on
      RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]

RewriteRule ^/typo3$ - [L]
RewriteRule ^/typo3/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* /index.php


    </Directory>
</VirtualHost>

我的vhost for ssl

<VirtualHost *:443>
    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/domain.crt
    SSLCertificateKeyfile /etc/apache2/ssl/domain.key
    SSLCertificateChainFile /etc/apache2/ssl/COMODOSSLCA.crt

    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
    SSLProtocol ALL -SSLv2
    SSLHonorCipherOrder On
    SSLCipherSuite AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH
    SSLInsecureRenegotiation off

    ServerName www.domain.at
    ServerAlias domain.at domain.gv.at www.domain.gv.at *.domain.at

    DocumentRoot /var/www/www/
    ErrorLog /var/log/apache2/domain.at-error.log
    CustomLog /var/log/apache2/domain.at-access.log combined

    <Directory /var/www/www>
      Options FollowSymLinks MultiViews -Indexes
      AllowOverride All
      Order allow,deny
      allow from all
    </Directory>
</VirtualHost>

但它不起作用。一些想法?

目标 - 删除.htaccess(我不想使用它) - 将domain.at和domain.gv.at重定向到https:// - 使用漂亮的网址来获取typo3

感谢分配

1 个答案:

答案 0 :(得分:0)

我可以解决问题。在我的情况下,目录是错误的。我不知道为什么但是它在我删除vHost(SSL和&#34;正常&#34;)之后现在有效。