【问题标题】:apache http redirect to https multiple rewriteconditionsapache http重定向到https多个rewriteconditions
【发布时间】:2015-02-03 03:46:22
【问题描述】:

我对更改 apache 设置和修改 httpd.conf 非常陌生。我已安装 SSL 并尝试将动态子域重定向到 HTTPS。

<VirtualHost *:80>
    ServerName catchall.mydomain.com
    ServerAlias *.mydomain.com
    VirtualDocumentRoot /var/www/html/places/

Options -MultiViews
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /places/index.php?request=$1 [L]
</VirtualHost>

<VirtualHost *:443>
    ServerName catchall.mydomain.com
    ServerAlias *.mydomain.com
    DocumentRoot /var/www/html/places/
    SSLEngine on
SSLCertificateFile /SUPERSECRET
SSLCertificateKeyFile /SUPERSECRET
SSLCertificateChainFile /SUPERSECRET
</VirtualHost>

如果我访问 example.mydomain.com,页面会正确加载,但不会重定向 HTTPS。我已经尝试了多种更改重写条件和规则的位置的变体,并且在进行更改后我将重新启动我的 httpd 服务。非常感谢任何帮助。

【问题讨论】:

    标签: apache ssl https virtualhost


    【解决方案1】:

    在越来越多地搜索 stackoverflow 之后,我能够缩小我的问题所在。

    Apache Multiple Rewrite Rules

    anubhava 友好地指出“L 仍然需要,因为 Last 标志用于标记每个重写规则的结束。规则的顺序也很重要。”

    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /places/index.php?request=$1 [L]
    

    现在这是正确的格式。我希望这对其他人有帮助。

    【讨论】:

      猜你喜欢
      • 2013-09-27
      • 2016-02-04
      • 2016-01-17
      • 2018-04-09
      • 2019-11-08
      • 2018-08-25
      • 2019-12-17
      • 2022-01-06
      • 2016-04-16
      相关资源
      最近更新 更多