【问题标题】:mod_rewrite in vHost and SSLvHost 和 SSL 中的 mod_rewrite
【发布时间】:2015-03-12 20:40:53
【问题描述】:

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

我的服务器是带有 apache2.2 的 debian 7.7。我有很多虚拟主机和一个 SSL 证书。所有域都指向同一个目录 (/var/www/www)。例如我有以下域:

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

我会将所有 .htaccess 内容移至他们的虚拟主机。

首先,我会将 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]

我也想要漂亮的 URL(即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>

我的 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使用漂亮的网址

感谢分配

【问题讨论】:

    标签: php apache .htaccess mod-rewrite ssl


    【解决方案1】:

    我可以解决问题。在我的情况下,目录是错误的。我不知道为什么,但在我删除 vHost(SSL 和“正常”)后它现在可以工作了

    【讨论】:

      猜你喜欢
      • 2017-04-01
      • 2012-02-29
      • 2015-10-23
      • 2023-03-04
      • 2011-05-22
      • 2013-07-14
      • 2015-01-25
      • 2010-12-01
      相关资源
      最近更新 更多