nginxÖÐÔõÑùÖض¨Ïò
ͨ¹ý nginx ¾ÙÐÐÖض¨ÏòµÄÒªÁìÓÐ 301 ÓÀÊÀÖض¨Ïò£¨¸üÐÂÁ´½Ó»òÒƶ¯Ò³Ã棩ºÍ 302 ÔÝʱÖض¨Ïò£¨´¦Öóͷ£¹ýʧ»òÔÝʱ¸ü¸Ä£©¡£ÉèÖÃÖض¨ÏòÉæ¼°ÔÚ server ¿éÖÐʹÓà location Ö¸Á¸ß¼¶¹¦Ð§°üÀ¨ÕýÔò±í´ïʽƥÅä¡¢ÊðÀíÖض¨ÏòºÍ»ùÓÚÌõ¼þµÄÖض¨Ïò¡£Öض¨ÏòµÄ³£¼ûÓÃ;°üÀ¨¸üРurl¡¢´¦Öóͷ£¹ýʧ¡¢½« http Öض¨Ïòµ½ https£¬ÒÔ¼°Ö¸µ¼Óû§»á¼ûÌض¨¹ú¼Ò»òÓïÑÔ°æ±¾¡£
ÔõÑùʹÓà Nginx Öض¨Ïò
Nginx ÊÇÒ»¸öÊ¢ÐÐµÄ Web ЧÀÍÆ÷£¬ËüÌṩÁ˶àÖÖÒªÁìÀ´Öض¨ÏòÇëÇó¡£Öض¨Ïò¹ØÓÚÐÞ¸ÄÍøÕ¾µÄ URL ½á¹¹¡¢´¦Öóͷ£¹ýʧ»ò½«Óû§Ö¸µ¼ÖÁÆäËûÒ³ÃæºÜÊÇÓÐÓá£
Öض¨ÏòÒªÁì
Nginx ÖÐÓÐÁ½ÖÖÖ÷ÒªµÄÖض¨ÏòÒªÁ죺
301 ÓÀÊÀÖض¨Ïò£º´ËÖض¨Ïòָʾä¯ÀÀÆ÷ÓÀÊÀÒƶ¯¸Ã URL¡£ËüÓÃÓÚ¸üйýʱµÄÁ´½Ó»òÒƶ¯Ò³Ãæµ½Ò»¸öеÄλÖá£
302 ÔÝʱÖض¨Ïò£º´ËÖض¨Ïòָʾä¯ÀÀÆ÷¸Ã URL ÔÝʱ¸ü¸Ä¡£ËüÓÃÓÚ´¦Öóͷ£¹ýʧ¡¢Î¬»¤»ò½«Óû§Ö¸µ¼ÖÁÆäËûÒ³Ãæ¡£
ÉèÖÃÖض¨Ïò
ÔÚ Nginx ÉèÖÃÎļþÖÐʹÓà server ¿éÉèÖÃÖض¨Ïò¡£ÒÔÏÂʾÀýÑÝʾÔõÑù½« example.com/old-page ÓÀÊÀÖض¨Ïòµ½ example.com/new-page£º
server { server_name example.com; location /old-page { return 301 https://example.com/new-page; } }
µÇ¼ºó¸´ÖÆ
¸ß¼¶Öض¨Ïò
Nginx »¹ÌṩÁËÒÔϸ߼¶Öض¨Ïò¹¦Ð§£º
ʹÓÃÕýÔò±í´ïʽ£º¿ÉÒÔʹÓÃÕýÔò±í´ïʽƥÅäÇëÇóµÄ URL ²¢¾ÙÐÐÖض¨Ïò¡£
ÊðÀíÖض¨Ïò£ºÔÊÐí½«ÇëÇóÖض¨Ïòµ½ÆäËûЧÀÍÆ÷¡£
»ùÓÚÌõ¼þµÄÖض¨Ïò£ºÆ¾Ö¤ÇëÇó±êÍ·¡¢Ð§ÀÍÆ÷±äÁ¿»òÆäËûÌõ¼þÖ´ÐÐÖض¨Ïò¡£
³£¼ûÓÃ;
Nginx Öض¨ÏòµÄ³£¼ûÓÃ;°üÀ¨£º
¸üйýʱµÄ URL
´¦Öóͷ£ 404 ¹ýʧ
½« HTTP ÇëÇóÖض¨Ïòµ½ HTTPS
½«Óû§Ö¸µ¼ÖÁ²î±ðµÄ¹ú¼Ò»òÓïÑÔ°æ±¾
ͨ¹ýʹÓà Nginx µÄÖض¨Ïò¹¦Ð§£¬Äú¿ÉÒÔÓÅ»¯ÍøÕ¾µ¼º½¡¢Ìá¸ßÓû§ÌåÑ鲢ƾ֤ÐèÒªÐÞ¸ÄÍøÕ¾½á¹¹¡£
ÒÔÉϾÍÊÇnginxÖÐÔõÑùÖض¨ÏòµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡