Ask for an nginx rewrite rule

Source: Internet
Author: User
Let's say I'm using a pan-resolved domain name of *.domain.com
Now I want to judge when the domain name is not www.domain.com and satisfies the condition for ([\w]{2,5}). Domain.com's two-level domain name is redirected to www.domain.com/domain.php?domain= ([\w]{ 2,5}) of the rewrite rule.

The first thing I wrote was this:
Set $domain ", if ($hots ~* ([\w]{2,5}). \domain\.com) {    set $domain $;} if ($domain!~" www ") {    rewrite ^ $domain \.domain\.com (. *) $ http://www.domain.com$1?domain= $domain last;}

Then the error is \w for the unsafe match.
And then I changed to:
Set $domain ", if ($hots ~*" ([\w]{2,5}). \domain\.com ") {Set $domain $ A,    } if ($domain! =" www ") {    rewrite ^ $doma In\.domain\.com (. *) $  http://www.domain.com$1?domain= $domain &query_string redirect;}


This time does not have the error, but cannot jump correctly.

So ask me where this code problem is, how should I rewrite it?


Reply to discussion (solution)

Then the error is \w for the unsafe match.
Rewrite [0-9a-za-z] to try this?

In addition, the resolution of the two-level domain name can be added to the PHP portal for more flexible functions.

Change to [0-9a-za-z] is also the same, because before he suggested \w unsafe I changed to this, but also invalid, and then added double quotation marks after the no problem, but the condition seems to judge not satisfied

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.