Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curly braces ({ and }) from Apache to Nginx rewrite rules.

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 ?

like image 346
Hugo H Avatar asked Feb 04 '13 10:02

Hugo H


1 Answers

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).

like image 113
regilero Avatar answered Sep 18 '22 12:09

regilero