【问题标题】:Redirect main domain, but not subdomain重定向主域,但不重定向子域
【发布时间】:2018-07-17 12:20:19
【问题描述】:

我在一个有多个卖家的网站上工作,每个卖家都有自己的子域。我想要做的是在访问主域(主主页)时将访问者重定向到登录页面,但在访问子域(卖家主页)时应该没有重定向。

myproject.com/重定向-> myproject.com/login/

但是

seller.myproject.com/ 不应重定向。

我用 htaccess 尝试了一些东西,但我最终也将子域重定向到 seller.myproject.com/login/

谁能指出我正确的方向,因为我对正则表达式很不好?

谢谢!

【问题讨论】:

    标签: regex .htaccess redirect url-redirection


    【解决方案1】:

    我认为您可以使用正则表达式解决您的问题,使用两个点作为用户在卖家页面上的标识。我不知道您使用的是哪种语言,但您可以从这里获得想法。

    String input="seller.myproject.com/";
    Pattern p=Pattern.compile(("[a-zA-z0-9]\\.[a-zA-z0-9]\\.com"));
    Matcher m=p.matcher(input);
    if(m.find())
    {
         //don't redirect
    }
    else
    {
         //redirect
    }
    

    【讨论】:

      【解决方案2】:

      好的,我刚刚找到了这个:

      https://stackoverflow.com/a/16886639/8694548

      这可行,但现在的问题是如何让所有子域都具有这种行为,而不是手动将它们放在那里。

      所以不是!^(foo|bar)\.example\.com$ > !^(*)\.example\.com$

      感谢您的帮助!

      【讨论】:

        【解决方案3】:

        好的,我现在知道了,这对我有用:

        # Redirect anything except subdomains RewriteCond %{HTTP_HOST} !^(.*)\.myproject\.com$ [NC]

        # Redirect to myproject.com/login, preserving the URI RewriteRule ^(.*)$ https://myproject.com/login/ [L,R=302]

        【讨论】:

          猜你喜欢
          • 2012-06-24
          • 2016-06-11
          • 1970-01-01
          • 2012-07-22
          • 2016-08-13
          • 1970-01-01
          • 2013-05-28
          • 1970-01-01
          • 2012-04-19
          相关资源
          最近更新 更多