Apache代理传递所有网址并仅重写一个特定网址

时间:2017-12-13 10:35:32

标签: apache .htaccess

我有一个在后端运行Ghost Blog引擎的网站。我将子域blog.domain.com配置为代理到ghost引擎(localhost:2368),但我需要验证谷歌搜索控制台中的子域,所以我需要blog.domain.com/googlefile.html返回一个特定的字符串(即domain.com/googlefile.html上提供了相同的字符串。我怎么做? 我的虚拟主机配置:

    ServerName blog.example.com
    ServerAlias *.blog.example.com

    #here is what I tried
    #RewriteEngine On
    #RewriteCond %{HTTP_HOST} blog\.example\.com
    #RewriteRule googlefile.html https://example.com/googlefile.html

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:2368/
    ProxyPassReverse / http://127.0.0.1:2368/

顺便说一下。所有域名都是https。

1 个答案:

答案 0 :(得分:1)

解决方案是启用SSLProxyEngine以便我可以代理https网址并使用mod_rewrite和代理忽略网址

    SSLProxyEngine On # enable SSLProxyEngine
    ServerName blog.example.com
    ServerAlias *.blog.example.com

    RewriteEngine On
    RewriteCond %{HTTP_HOST} blog\.example\.com
    RewriteRule googlefile.html https://example.com/googlefile.html [P]

    ProxyPreserveHost On
    ProxyPass googlefile.html ! # ignore the rewrited url
    ProxyPass / http://127.0.0.1:2368/ 
    ProxyPassReverse / http://127.0.0.1:2368/