nginxα¾²Ì¬ÔõôÉèÖÃ
ÎÊÌ⣺ʲôÊÇ nginx α¾²Ì¬ÉèÖã¿ÃÕµ×£ºÎ±¾²Ì¬ÊÇͨ¹ýÖØд url£¬½«¶¯Ì¬ url ת»»Îª¾²Ì¬ url£¬´Ó¶ø¸ÄÉÆÍøÕ¾µÄ seo ºÍÐÔÄÜ¡£°ì·¨£ºÌí¼Ó rewrite Ä£¿é£»½¨Éèα¾²Ì¬¹æÔò£»¼¤»î rewrite Ä£¿é£»ÖØÆô nginx¡£
nginx α¾²Ì¬ÉèÖÃ
ʲôÊÇα¾²Ì¬£¿
α¾²Ì¬ÊÇͨ¹ýÔÚЧÀÍÆ÷¶Ë¶Ô URL ¾ÙÐÐÖØд£¬½«¶¯Ì¬ URL ת»»Îª¾²Ì¬ URL£¬´Ó¶øÈö¯Ì¬ÍøÕ¾¿´ÆðÀ´Ïñ¾²Ì¬ÍøÕ¾¡£Õâ¿ÉÒÔ¸ÄÉÆÍøÕ¾µÄ SEO ºÍÐÔÄÜ¡£
Nginx α¾²Ì¬ÉèÖð취£º
1. ÔÚ nginx ÉèÖÃÎļþÖÐÌí¼Ó rewrite Ä£¿é
load_module rewrite_module modules/ngx_rewrite.so;
µÇ¼ºó¸´ÖÆ
2. ½¨Éèα¾²Ì¬¹æÔò
ÔÚÉèÖÃÎļþÖÐÌí¼Ó rewrite Ö¸Á¹æÔòÈçÏ£º
# ½«´øÓÐ .html ºó׺µÄ URL ÖØдΪ index.php rewrite ^(.+).html$ /index.php$1 last;
µÇ¼ºó¸´ÖÆ
´Ë¹æÔò½«½«ËùÓдøÓÐ “.html” ºó׺µÄ URL ÖØдΪÒÔ “index.php” ¿ªÍ·¡¢ºó׺ΪÔÀ´µÄ URL ºó׺µÄРURL¡£
3. ¼¤»îÖØдģ¿é
ÔÚ server ¿éÖУ¬¼¤»î rewrite Ä£¿é£º
server { ... rewrite_module on; ... }
µÇ¼ºó¸´ÖÆ
4. ÖØÆô nginx
ÐÞ¸ÄÍê³Éºó£¬ÐèÒªÖØÆô nginx ЧÀÍÆ÷ÒÔÓ¦Óøü¸Ä¡£
ʾÀý£º
ÒÔÏÂʾÀý½«ËùÓдøÓÐ “.html” ºó׺µÄ URL ÖØдµ½ “index.php”£º
rewrite ^(.+).html$ /index.php$1 last;
µÇ¼ºó¸´ÖÆ
×¢ÖØ£º
α¾²Ì¬¹æÔòÖУ¬$1 ´ú±íµÚÒ»¸ö²¶»ñ×é¡£
last ±ê¼ÇÈ·±£¹æÔòÖ»Ó¦ÓÃÒ»´Î¡£
ÄúÐèҪƾ֤×Ô¼ºµÄÍøÕ¾ÐèÒªÐ޸ĹæÔò¡£
ÒÔÉϾÍÊÇnginxα¾²Ì¬ÔõôÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡