我試圖強制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