nginx短url为mediawiki

我正在尝试为MediaWiki网站做简短的url。 wiki位于mydir子目录( http://www.example.com/mywiki )。 我已经在/etc/nginx/sites-available设置了重写,以便example.comredirect到example.com/mywiki。

目前这个url就像http://www.example.com/mywiki/index.php?title=Main_Page 。 我想清理url,使其看起来像http://www.example.com/mywiki/Main_Page 。 我这样做有点麻烦。 我不熟悉正则expression式或nginxconfiguration文件使用的语法。

这是我现在有:

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

第二次改写显然是破碎的。 它基于MediaWiki文档中的Page title – nginx rewrite – root访问

当我尝试加载网站时,浏览器告诉我,我得到无限的redirect。 有谁应该怎么去解决这个问题? 或者说,实现这个的正确方法是什么?所有这些符号是什么意思?

这是他们在那里的一个非常有趣的expression。 他们的主要手册网页的短URL有这样的说:

这些指南是旧的,几乎是完全不好的build议。

无论如何,让我们看看我们是否可以简化一下。

 rewrite ^/wiki/([^\?]*) /mywiki/index.php?title=$1&$args last; 

请注意,您不能覆盖“漂亮”path(您已经放置在location块中,所以让我们运行它)和物理path; 规范是使用/wiki/作为漂亮的path(你的$wgArticlePathconfiguration)和/w/作为物理path(你的$wgScriptPathconfiguration)。

总而言之,就是这样的:

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

…并且您将需要以某种forms显示PHP处理,如同他们在示例中所示,以及使用适当的$wgArticlePath$wgArticlePath设置更新Settings.php ,以及将$wgUsePathInfo设置为true。