nginx short urls for mediawiki

Posted by William on Server Fault See other posts from Server Fault or by William
Published on 2012-06-28T04:12:42Z Indexed on 2012/06/28 9:17 UTC
Read the original article Hit count: 235

Filed under:
|
|

I am trying to do short URLs for a MediaWiki site. The wiki is in a subdirectory mydir (http://www.example.com/mywiki). I've already set up rewrites in /etc/nginx/sites-available so that example.com redirects to example.com/mywiki.

Currently the URL is like http://www.example.com/mywiki/index.php?title=Main_Page. I want to clean up the url so that it looks like http://www.example.com/mywiki/Main_Page. I am having quite a bit of trouble doing this. I am not familiar with regular expressions or the syntax that the nginx config files use.

This is what I currently have:

server_name example.com www.example.com;

location / 
{
  rewrite ^.+ /mywiki/ permanent;
}

location /wiki/ 
{
  rewrite ^/mywiki/([^?]*)(?:\?(.*))? /mywiki/index.php?title=$1&$2 last;
}

The second rewrite is obviously the one that's broken. It is based off of Page title -- nginx rewrite--root access in the MediaWiki documentation.

When I try to load the site, the browser tells me I get infinite redirects. Does anyone who how I should go about fixing this issue? Or rather, what is the correct way to implement this, and what do all those symbols mean?

© Server Fault or respective owner

Related posts about nginx

Related posts about mediawiki