nginx Directive rewrite is not terminated

October 17, 2014
linuxweb

I have been setting up some sites on nginx today (moving from an apache server) and have been pretty happy with how an Apache rewrite rule like:

RewriteRule /foo/([0-9]+)/ /foo.cfm?id=$1

Can be done in nginx like this:

rewrite /foo/([0-9]+)/ /foo.cfm?id=$1;

This was working great until I ran into this error:

[emerg] 4603#0: directive "rewrite" is not terminated by ";" in /etc/nginx/sites-enabled/example.com.conf:26

But the line referenced did end with a semicolin!

It turns out the problem was that my rewrite rule had {} in it, for example:

rewrite ^/archive/([0-9]{4})/ /archive.cfm?year=$1;

Replacing the {4} with simply a + worked (though is less precise).



Related Entries

1 person found this page useful, what do you think?

Comments

I came across this SO question/answer, http://stackoverflow.com/questions/14684463/curly-braces-and-from-apache-to-nginx-rewrite-rules that refers to wrapping the regex in double quotes to make use of the brackets and eliminate the semicolon error.
Did you try {4,4}?
Not sure my last comment took? but I believe you can avoid the semicolon error and keep the intended regex by wrapping it in double quotes.

So,

rewrite "^/archive/([0-9]{4})/ /archive.cfm?";
Thanks Dan & Tony I didn't look into alternatives too closely but thanks for the suggestions I'll give them a try when I have a min.

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?