Nginx rewrite for link shortener and Wordpress

Posted by detusueno on Stack Overflow See other posts from Stack Overflow or by detusueno
Published on 2010-03-14T02:38:33Z Indexed on 2010/03/14 2:45 UTC
Read the original article Hit count: 361

Filed under:
|

I'm a complete newbie to Nginx, so much so that I followed a online guide to do most of my server setup. I'm trying to learn but I'm still a ways away from understanding it all.

So what I'm trying to create is a link shortener that redirects (example.com/x) to (example.com/short.php?id=x). Keep in mind that I'm also running a Wordpress blog on the same domain and plan on using the redirects/shortening for external links. The guide has so far had me add the following rewrites to enable Wordpress pretty URLs:

  # WordPress pretty URLs: (as per dominiek.com)
  if (-f $request_filename) {
  break;
  }
  if (-d $request_filename) {
  break;
  }
  rewrite ^(.+)$ /index.php?q=$1 last;


  # Enable nice permalinks for WordPress: (as per Yawn.it)
  error_page  404  = //index.php?q=$uri;

And if it matters any, it was saved at (/usr/local/nginx/conf/wordpress_params.regular).

Additionally, my Wordpress link structure adds "news" to all internal links (example.com/news/post-blah, example.com/news/category, ect.). What's the best way to tackle this setup?

© Stack Overflow or respective owner

Related posts about nginx

Related posts about Wordpress