【问题标题】:How to redirect to the correct domain with Apache?如何使用 Apache 重定向到正确的域?
【发布时间】:2019-07-09 03:32:45
【问题描述】:

我的服务器的 8080 端口上有一个可用的应用程序。如果所有用户使用 IP 地址 (http://0.0.0.0:8080) 或任何其他指向服务器的域名访问应用程序,我想将所有用户重定向到 myserverhostname:8080。

我想在不添加任何虚拟主机的情况下使用 .htaccess 进行重定向。当前 vhost 已经在端口 8080 上使用任何主机名正确服务。

我当前的 .htaccess 给我重定向循环。

这里是:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^server1.example.com$ [NC]
RewriteRule ^(.*)$ https://server1.example.com:8080/$1 [L,R]

我认为 RewriteCond 没有看到任何区别,当 %{HTTP_HOST} 已经是 server1.example.com 时应该禁用重定向。

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    默认的 web HTTP 端口是 80,所以检查这个规则:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://server1.example.com:8080/$1 [R=301,L]
    

    【讨论】:

    猜你喜欢
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多