Nginx 正则表达式除了所有路径
Nginx regexp all paths expect
我有 3 种路径 /api
、/
、/some_path_here
如果用户请求的页面路径为空 (/
),我想重定向到登录。
所以我有一个这样的配置文件
location /api {
try_files $uri $uri/ /index.php?$args;
}
location /[0-9a-z] {
try_files $uri $uri/ /index.html;
root /var/www/cabinet/client/dist;
}
location / {
return 301 https://my_domain.com/login;
}
但是当尝试请求 https://my_domain.com/
时,它重定向到 https://my_domain.com/login
并出现错误 ERR_TOO_MANY_REDIRECTS
如何解决这个错误?
这是一个解决方案
location /api {
try_files $uri $uri/ /index.php?$args;
}
location / {
try_files $uri $uri/ /index.html;
root /var/www/cabinet/client/dist;
}
location = / {
return 301 $scheme://$server_name/login/;
}
我有 3 种路径 /api
、/
、/some_path_here
如果用户请求的页面路径为空 (/
),我想重定向到登录。
所以我有一个这样的配置文件
location /api {
try_files $uri $uri/ /index.php?$args;
}
location /[0-9a-z] {
try_files $uri $uri/ /index.html;
root /var/www/cabinet/client/dist;
}
location / {
return 301 https://my_domain.com/login;
}
但是当尝试请求 https://my_domain.com/
时,它重定向到 https://my_domain.com/login
并出现错误 ERR_TOO_MANY_REDIRECTS
如何解决这个错误?
这是一个解决方案
location /api {
try_files $uri $uri/ /index.php?$args;
}
location / {
try_files $uri $uri/ /index.html;
root /var/www/cabinet/client/dist;
}
location = / {
return 301 $scheme://$server_name/login/;
}