我试图强制HTTPS传入连接,同时也重定向到一个特定的URL的所有请求。Nginx重定向为http和https
期望的结果:
http://example.com - >https://example.com/dir
https://example.com - >https://example.com/dir
这里是什么,我相信应该工作,但说有太多的重定向。
server {
listen 80;
listen 443 ssl;
server_name example.com;
location/{
return 301 https://$server_name/dir$request_uri;
}
location /dir {
try_files $uri $uri/ /index.php?$args;
}
任何帮助非常感谢!
如何将重定向写入/ dir部分呢?我会放弃https吗? –
像这样的东西应该可以工作 - 重写^((?!dir /)\ S +)$ dir/$ 1 permanent;'。不太确定正则表达式,虽然没有测试过 – avpav