【问题标题】:Redirect using virtual host domain name beginning with https使用以 https 开头的虚拟主机域名进行重定向
【发布时间】:2023-12-19 22:05:01
【问题描述】:

我正在尝试将 ME.com 或 www.ME dot com 重定向到 https://NOTME dot com。 下面的代码有效,但是当我输入https://ME dot com 时,它不会转到https://NOTME dot com。我收到一个页面不安全的错误。 代码如下:

<VirtualHost *:80>
ServerAdmin admin@ME dot com
ServerName ME dot com
    ServerAlias www dot ME dot com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www dot ME dot com
RewriteRule ^/(.*)$ http://NOTME dot com/$1 [L,R=301]
Redirect permanent / https://NOTME dot com/
DocumentRoot /var/www/xxx/xxx/
<Directory />
    Options FollowSymLinks
    AllowOverride all
</Directory>
<Directory /var/www/xxxx/xxxxx/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
            SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
            nokeepalive ssl-unclean-shutdown \
            downgrade-1.0 force-response-1.0
    # MSIE 7 and newer should be able to use keepalive
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown        

另外请注意,我设置 ME.com 有一个我删除的 https 证书,该证书设置在虚拟主机端口 443。我还可以将证书返回给它吗? 此外,ME.com 和 NOTME.com 都在同一个服务器 IP 上。

【问题讨论】:

    标签: apache mod-rewrite redirect virtualhost


    【解决方案1】:

    这就是我解决这个问题的方法:

    <VirtualHost *:443>
    ServerAdmin x@ME.com
    ServerName ME.com
    ServerAlias www.ME.com
    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^www.ME.COM/$
    RewriteRule ^/(.*)$ https://NOTME.COM/$1 [L,R=301]
    Redirect permanent / https://NOTME.COM/
    
    SSLEngine on
    SSLCertificateFile /xxxxxxxxxxxx.crt
    SSLCertificateKeyFile /xxxxxxxxxxxx.key
    SSLCertificateChainFile /xxxxxxxxxxxxxx.crt
    

    实际上解决方案是永久重定向到 NOTME dot com

    【讨论】:

      最近更新 更多