Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert mod_rewrite (QSA option) to Nginx equivalent?

I'm looking to convert the following mod_rewrite rule to the Nginx equivalent:

RewriteRule ^foo/(.*)$ /bar/index.php?title=$1 [PT,L,QSA]
RewriteRule ^foo/*$ /bar/index.php [L,QSA]

So far I have:

rewrite ^foo/(.*)$ /bar/index.php?title=$1&$query_string last;
rewrite ^foo/?$ /bar/index.php?$query_string break;

The problem is (I think!) that the query string doesn't get appended. I haven't found a way to port the QSA argument to Nginx.

like image 697
jumoel Avatar asked Nov 11 '08 10:11

jumoel


2 Answers

QSA is automatic in NGINX.

If you don't want it, add ? to the end of your new location

rewrite ^/foo /bar/index.php? last;

like image 180
Mikeage Avatar answered Nov 06 '22 11:11

Mikeage


These rewrite rules made the scripts work:

rewrite ^/foo/([^?]*)(?:\?(.*))? /bar/index.php?title=$1&$2;
rewrite ^/foo /bar/index.php;
like image 34
jumoel Avatar answered Nov 06 '22 09:11

jumoel