15

I have this rules that sucessfully worked on apache but return error or nginx :

rewrite ^/saison-([0-9]{1})$ /pages.php?cat_page=saison-$1&season=$1 last;
rewrite ^/saison-([0-9]{1})/([a-z0-9-]+)$ /evenements.php?season=$1&title=$2 last;
rewrite ^/saison-([0-9]{1})/([a-z0-9-]+)/([a-z0-9-]+)/([a-z0-9-]+)$ /evenements.php?season=$1&title=$2&place=$3&date=$4 last;
rewrite ^/saison-([0-9]{1})/([a-z0-9-]+)/([a-z0-9-]+)/([a-z0-9-]+)/([a-z]+)$ /evenements.php?season=$1&title=$2&place=$3&date=$4&view=$5 last;

I got :
*Restarting nginx: [emerg]: directive "rewrite" is not terminated by ";" in /path/rwrules.nginx:1

If I remove this 4 lines from my rewrite rules, it works. What's the problem ?

Hugo H
  • 6,029
  • 5
  • 37
  • 57

1 Answers1

34

Read this documentation. especially:

Note: for curly braces( { and } ), as they are used both in regexes and for block control, to avoid conflicts, regexes with curly braces are to be enclosed with double quotes (or single quotes).

So for example the line :

rewrite ^/saison-([0-9]{1})$ /pages.php?cat_page=saison-$1&season=$1 last;

should be:

rewrite "^/saison-([0-9]{1})$" /pages.php?cat_page=saison-$1&season=$1 last;

This should remove the ";" syntax error (for the rule I didn't check they are functionnaly valid).

regilero
  • 29,806
  • 6
  • 60
  • 99
  • @regilero you should answer this Stack Exchange question I just put up, as your answer here fixed it for me. So thanks! http://serverfault.com/questions/569126/nginx-mutliple-rewrite-rules-per-location – Pete Jan 22 '14 at 17:24
  • Oh, well it fixed part of it, had a syntax error but I'm still stuck on my question. Still, thanks. – Pete Jan 22 '14 at 17:40