Can someone convert this Apache mod_rewrite rule to something Nginx can understand?

Discussion in 'Nginx' started by subdivisions, Feb 19, 2010.

  1. #1
    RewriteEngine On
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.mydomain\.com$ [NC]
    RewriteRule (.*) /forums/$1 [L]
    Code (markup):
    If someone could convert that to nginx syntax, I'd really appreciate it.

    Thanks!
     
    subdivisions, Feb 19, 2010 IP
  2. sahabcse

    sahabcse Well-Known Member

    Messages:
    272
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    140
    #2
    #ignored: condition 0
    if ($http_host !~* "^www\.mydomain\.com$"){
    set $rule_0 2$rule_0;
    }
    if ($http_host ~* "^(www\.)?([^\.]+)\.mydomain\.com$"){
    set $rule_0 3$rule_0;
    }
    if ($rule_0 = "321"){
    rewrite /(.*) /forums/$1 last;
    }

    I don't know its working properly or not. I have done some conversion for my site using the url http://www.anilcetin.com/convert-apache-htaccess-to-nginx/. Its worked for me
     
    sahabcse, Feb 19, 2010 IP
  3. subdivisions

    subdivisions Well-Known Member

    Messages:
    1,021
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    145
    #3
    Thanks! Rep'd.
     
    subdivisions, Feb 20, 2010 IP
  4. raffo77

    raffo77 Active Member

    Messages:
    234
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    Look here for a good configuration of Nginx
    https://www.rv89.eu/forum/index.php?/topic/13-setup-nginx-as-http-deamon-with-vhosts/
     
    raffo77, Feb 20, 2010 IP