Welcome! Log In Create A New Profile

Advanced

Redirecting urls with query strings via map module

Posted by djwyx 
Redirecting urls with query strings via map module
April 09, 2014 02:34PM
Hi all,

I'm a bit new to nginx, and I haven't been able to find documentation about this precise problem I've been having, apologize if this has already been covered:

I set up a static mirror of a Wordpress blog on nginx, but some of the old urls end up looking like "/?p=100" instead of their "pretty" permalinks. So I need to permanently redirect "/index.html?p=100" or "/?p=100" to "/2014/04/blog-post-one-hundred/" so that the old links work.

Since there are only about 150 such URLs, I figured I could make a map to handle this problem, but it's not working and I suspect it has to do with nginx's feelings about query strings and regexes.

How should I go about doing this? I was trying stuff like

map $uri $new {
'/?p=100' '/2014/04/blog-post-one-hundred/';
}

if ($arg_p) {
rewrite ^ $new
}

but obviously that hasn't worked (I see "the rewritten URI has a zero length" in the logs). Any ideas?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 301
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready