Nginx 使用部分请求重定向到不同的位置 header
Nginx redirect to different location with part of the request header
我想将某些请求重定向到不同的位置,但有一部分请求 header,例如:
https://example.com/something/value ---> https://example.com/something/index.php?var=value
pseudo-code:
location ^~ /something/$value {
return 301 https://$host/something/index.php?var=$value;
}
location
只需要匹配URI中不变的那部分。如果/something/index.php
和/something/value
是相同的前缀,那么就不要使用^~
修饰符,否则会找不到PHP文件。有关详细信息,请参阅 this document。
使用 rewrite
捕获 URI 的 "value" 部分并将其附加为参数。
例如:
location /something/ {
rewrite ^/something/(.*)$ /something/index.php?var= last;
}
如果您想要外部重定向,请使用 rewrite...permanent
而不是 rewrite...last
。有关详细信息,请参阅 this document。
我想将某些请求重定向到不同的位置,但有一部分请求 header,例如: https://example.com/something/value ---> https://example.com/something/index.php?var=value
pseudo-code:
location ^~ /something/$value {
return 301 https://$host/something/index.php?var=$value;
}
location
只需要匹配URI中不变的那部分。如果/something/index.php
和/something/value
是相同的前缀,那么就不要使用^~
修饰符,否则会找不到PHP文件。有关详细信息,请参阅 this document。
使用 rewrite
捕获 URI 的 "value" 部分并将其附加为参数。
例如:
location /something/ {
rewrite ^/something/(.*)$ /something/index.php?var= last;
}
如果您想要外部重定向,请使用 rewrite...permanent
而不是 rewrite...last
。有关详细信息,请参阅 this document。