Nginx 重定向
本文最后更新于:2024年3月18日 凌晨
Nginx 重定向
301永久重定向
1 2 3 4 5
| server { listen 80; server_name example.com; return 301 https://www.example.com$request_uri; }
|
302临时重定向
1 2 3 4 5 6 7 8
| server { listen 80; server_name yourdomain.com; rewrite ^(.*)$ https://$host$1; location / { index index.html index.htm; } }
|
根据客户端重定向
1 2 3 4 5 6 7 8 9 10
| server { listen 80; server_name example.com; index index.html index.php; root html; if ( $http_user_agent ~* "(Android)|(iPhone)|(Mobile)|(WAP)|(UCWEB)" ){ rewrite ^/$ http://www.m.example.com permanent; } }
|