【问题标题】:Mask subdomain using .htaccess使用 .htaccess 屏蔽子域
【发布时间】:2018-11-10 03:21:14
【问题描述】:

我想使用 .htaccess 将我的子域屏蔽到我的主域上的特定 url。

例如:https://sub.example.com显示https://www.example.com/page/12345的内容。 而且网址还是https://sub.example.com

我在 .htaccess 中有以下内容:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com
RewriteRule ^https://sub\.example\.com https://www\.example\.com/page/12345

但是如果我去https://sub.example.com,它会显示https://www.example.com的内容。似乎无法弄清楚出了什么问题。请帮忙!

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    实际上,您希望在不重定向的情况下进行重写。这需要在 Apache 的 httpd.conf 中启用 mod_proxy 和 mod_rewrite。

    然后,重写应该是这样的:

    Options +FollowSymLinks -MultiViews 
    RewriteEngine On
    RewriteCond %{HTTP_HOST}  ^sub\.example\.com$ [NC]
    #only when there is query string and https on, if needed
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{HTTPS} =on
    RewriteRule ^$ https://www.example.com/page/12345? [R=301,NE,NC,L]
    

    参考:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-08
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 2019-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多