php - vHost 和 SSL 中的 mod_rewrite

标签 php apache .htaccess mod-rewrite ssl

我搜索了整个网络,但没有找到解决我的问题的方法。

我的服务器是 debian 7.7 和 apache2.2。我有很多虚拟主机和一个 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 使用漂亮的 url

谢谢分配

最佳答案

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

关于php - vHost 和 SSL 中的 mod_rewrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27946754/

相关文章:

.htaccess - 如果读取权限受限,搜索引擎能否读取 robots.txt?

javascript 数组返回 [object Window] 而不是数组内容

php - 检查 MySQL 数据库中是否存在没有唯一键的电子邮件地址

php,mysqli_stmt::bind_param() [mysqli-stmt.bind-param]:变量数量与准备好的语句中的参数数量不匹配

javascript - PushState 改变浏览器 URL 后刷新页面;它告诉我页面不存在

apache - fatal error : Uncaught exception 'Zend_Cache_Exception' with message > 'cache_dir must be a directory'

php - 如何在 php 中执行模式为数组的 preg_match?

apache - Amazon AWS EC2 环境中 Apache 上虚拟主机的 SSL

apache - .htaccess文件用什么语言编写?

.htaccess - 仅当确切的 url 匹配时如何重定向?