我有一个 WordPress 博客,我想将所有请求重定向到某个帖子/页面,不包括 js、css(和图像)。
所以 example.com/some-post/ 必须(暂时)重定向到 exmaple.com/catch-all/
我正在玩这个,但似乎不太好用(我不确定我是否需要使用 $uri):
if ($uri !~ \.css$) {
set $redi C;
}
if ($uri !~ \.js$) {
set $redi "($redi)J";
}
if ($uri !~ /catch-all/$) {
set $redi "($redi)P";
}
if ($redi = CJP) {
rewrite ^(.*)$ https://example.com/catch-all/ last;
return 302;
}
Run Code Online (Sandbox Code Playgroud)
使用空location块来避免某些请求的重定向:
location ~ \.css$ {}
location ~ \.js$ {}
location /catch-all/ {}
location / {
rewrite ^(.*)$ /catch-all/ redirect;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5800 次 |
| 最近记录: |