【问题标题】:Htacces redirect specific slugsHtaccess 重定向特定的 slug
【发布时间】:2019-08-14 14:36:56
【问题描述】:

我正在尝试配置 .htaccess 以强制重定向到特定子域。

假设我有一个带有许多子域的 example.com 域,所以最后我有这个域和子域:

  • example.com
  • www.example.com
  • demo.example.com
  • test.example.com

我想要的是打开链接example.com/testwww.example.com/test,htaccess 应该强制重定向到test.example.com,而对于其他域它不应该。

所以基本上:

  • example.com/test -> test.example.com(重定向)
  • www.example.com/test -> test.example.com(重定向)
  • demo.example.com/test -> demo.example.com/test(无重定向)
  • test.example.com/test -> test.example.com/test(无重定向)

【问题讨论】:

    标签: apache .htaccess redirect url-rewriting


    【解决方案1】:

    您可以在站点根目录 .htaccess 中使用此重定向规则:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com)$ [NC]
    RewriteRule ^test(/.*)?$ http://test.%1$1 [L,NC,R=301,NE]
    

    【讨论】:

      猜你喜欢
      • 2016-03-02
      • 2013-07-02
      • 2015-07-28
      • 2012-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多