我已经沮丧了好几天试图弄清楚这一点,所以非常感谢任何建议/帮助!
我最近添加了一个名为“/links
到网站”的部分somehost.com但似乎无法让重写规则适用于此目录(见下文)。域的所有其他路径均运行良好(例如somehost.com/browse/video/whatever重定向至somehost.com/by/whatever/很好),并且所有其他重写规则似乎仍然运行良好,只是location /links/
我的配置文件中新添加的部分出现了问题。
以下配置在第 27 行失败——使用时我得到的错误service nginx restart
是:指令“rewrite”没有以“;”终止 但我可以看到最后一行以 ; 结尾,所以我不确定哪里出了问题。也许是正则表达式出了问题?
我的 nginx 配置如下。有什么想法可以改变哪些地方来获取类似这样的 URLsomehost.com/links/page/3或者somehost.com/links/tag/sometopic/page/2在职的?
谢谢!
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;
}
}
答案1
在重写的第一个正则表达式中,美元位于引号之外。