我已经沮丧了几天想弄明白这一点,所以任何意见/帮助将不胜感激!
我最近在somehost.com上添加了一个名为/links到某个站点的部分,但似乎无法得到这个目录的重写规则(见下文)。 域的所有其他path工作正常(例如说一些hosthost /浏览器/video/无论redirect到somehost.com/by/whatever/罚款)和所有其他重写规则似乎仍然工作很好,这只是新添加location /links/部分我的conf在东西分崩离析。
下面的conf在第27行失败 – 使用service nginx restart时得到的错误是: 指令“rewrite”没有以“;”结尾。 但是我可以看到终点线终止于一个; 所以我不确定有什么问题。 也许正则expression式的东西?
我的nginx conf在下面。 任何想要改变什么来获取像somehost.com/links/page/3或somehost.com/links/tag/sometopic/page/2工作的url?
谢谢!
server { server_name somehost.com; listen 80; root /var/www/somehost.com; include /etc/nginx/php.conf; location / { index index.php; access_log /var/log/nginx/somehost.com.log; #handle old variable redirects first, before dealing with current permalinks rewrite ^/?browse/video/(.*) /by/$1 permanent; #set a 30-day expires header on static files for cache if (-f $request_filename) { expires 30d; break; } #do current permalinks with args try_files $uri $uri/ /index.php?$args; } #handle static redirects from old URLs and rewrite location /browse/title { rewrite ^(.*)$ /browse/?orderby=title redirect; } location /browse/featured { rewrite ^(.*)$ /by/featured/ permanent; } #handle /links permalinks etc location /links/ { rewrite "tag/(.+)/page/([0-9]{1,})/s/([^/]+)(/)?"$ /?tag=$1&page=$2&s=$3 break; rewrite "tag/(.+)/page/([0-9]{1,})(/)?" /?tag=$1&page=$2 break; rewrite tag/(.+)/s/([^/]+)(/)? /?tag=$1&s=$2 break; rewrite tag/([^/]+)(/)? /?tag=$1 break; rewrite rss/([^/]+) /rss.php?tag=$1 break; rewrite rss /rss.php break; rewrite "page/([0-9]{1,})/s/([^/]+)" /index.php?page=$1&s=$2 break; rewrite "page/([0-9]{1,})" /index.php?page=$1 break; rewrite go/([0-9]+) /ir.php?id=$1 break; } }
在重写的第一个正则expression式中,美元不在引号之内。