tokmak
tokmak

Reputation: 1509

Rewrite rule fir NGINX

I'm pretty bad in reg expression and nginx rewrite rules. I need help to figure rewrite rules for the following situation for NGINX.

http://example.com/blog/category1/postname => http://example.com/category1/postname
http://example.com/blog/category1/helloworld => http://example.com/category1/helloworld

Thank you in advance!

Upvotes: 0

Views: 151

Answers (1)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42799

this one is pretty simple, you just want to tell nginx to ignore the word blog ( and I'll assume it has to be followed with the word category1 )

rewrite ^/category1/(.*) /blog/category1/$1 last;
#       |      |      |     |            |    |
#      [1]    [2]    [3]   [4]          [5]  [6]

[1]: URL begins with
[2]: category1
[3]: capture all that follows
[4]: add blog
[5]: add the rest of the URL ( that we captured in [3] )
[6]: stop the rewrite and process the new URL and any other matching rewrites.

Upvotes: 1

Related Questions