我在http://site.com/blog上托管了一个博客。
如何指示 nginx 重写来自site.comto 的请求site.com/blog?
这不应该是永久性的。
location = / {
rewrite ^ http://site.com/blog/ redirect;
}
Run Code Online (Sandbox Code Playgroud)
这只会专门为根执行请求。如果您需要捕获所有内容(重定向http://site.com/somearticle/something.html到http://site.com/blog/somearticle/something.html),那么您将需要更多相关内容:
location /blog/ {
# Empty; this is just here to avoid redirecting for this location,
# though you might already have some config in a block like this.
}
location / {
rewrite ^/(.*)$ http://site.com/blog/$1 redirect;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
试试这个:
location = / {
return 301 /blog/;
}
Run Code Online (Sandbox Code Playgroud)
这里的关键是“=”符号。
| 归档时间: |
|
| 查看次数: |
33927 次 |
| 最近记录: |