Alasdair
Alasdair

Reputation: 14103

Nginx Regex URL Rewrite Not Working

Why on earth does this not work when all my other URL rewrites work perfectly:

rewrite "^/search/?\?q(.+)$" /search.php?q$1 break;

I did restart nginx and all of that.

Upvotes: 0

Views: 894

Answers (1)

Chuan Ma
Chuan Ma

Reputation: 9914

Rewrite only works on uri path. You don't need to rewrite the query string part because by default it's automatically attached to the new url.

rewrite /search /search.php break;

For example, /search?q=something will be written to /search.php?q=something.

See http://wiki.nginx.org/HttpRewriteModule#rewrite for more detail. This line below addresses your question

Also rewrite operates only on path, not parameters.

Upvotes: 2

Related Questions