Hugo H
Hugo H

Reputation: 6362

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 ?

Upvotes: 18

Views: 10396

Answers (1)

regilero
regilero

Reputation: 30526

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

Upvotes: 39

Related Questions