【问题标题】:How to point a URL to a different address for static content and point it back to the same address如何将 URL 指向静态内容的不同地址并将其指向同一地址
【发布时间】:2018-09-18 16:36:05
【问题描述】:

我有一个网址 www.example.com。这应该指向页面 www.test.com 并显示 www.test.com 中的内容,但在 URL 框中它应该显示 www.example.com

我在 vhost.conf 中用于重写文件的当前配置是

RewriteEngine on
SSLProxyEngine on
RewriteRule ^/(.*)$ www.test.com
ProxyPassReverse  / www.exapmle.com

【问题讨论】:

  • 您应该使用域别名:ServerName www.test.com ServerAlias test.com ServerAlias www.example.com ServerAlias example.com

标签: apache url url-rewriting


【解决方案1】:

由于您想将整个 www.example.com 重定向到 www.test.com,请执行以下操作:

ProxyPass        "/"    "http://www.test.com"
ProxyPassReverse "/"    "http://www.test.com"

就像@paglofr 指出的那样,如果你控制了这两个网站,你可以这样做:

  • 将www.example.com的DNS中的IP改为www.test.com的IP
  • 在 www.test.com 的 VirtualHost 中,添加:

    ServerAlias www.example.com
    
  • 删除 VirtualHost www.example.com

【讨论】:

  • 我无法控制这些网站。我对其他域有相同的配置,在 Rewriterule 的末尾添加了一个 [P] 标志,它工作正常。但是,对于这个特定的域,它会给出 502 代理错误。
  • 日志中的任何内容(在尝试之前设置您的LogLevel debug)。当使用带有标志[P]RewriteRule 时,您不需要ProxyPassReverse。哦,我的回答有误,请再看一遍。我两次都输入了ProxyPass。并确保加载 mod_proxy 和 mod_proxy_http。
猜你喜欢
  • 2019-09-07
  • 2019-05-10
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
  • 1970-01-01
  • 2019-04-07
  • 1970-01-01
  • 2016-10-06
相关资源
最近更新 更多