NginxÖØдURLÉèÖÃÊÃ÷ÈÕ½£¬ÓÅ»¯ÍøÕ¾½á¹¹ºÍSEO
nginxÖØдurlÉèÖÃÊÃ÷ÈÕ½£¬ÓÅ»¯ÍøÕ¾½á¹¹ºÍseo
СÐò£º
ÔÚÏÖ´ú»¥ÁªÍøʱ´ú£¬¹Å°åµÄ¾²Ì¬ÍøÒ³ÒѾÎÞ·¨Öª×ãÓû§µÄÐèÇó¡£ÎªÁËÌṩ¸üºÃµÄÓû§ÌåÑ飬Ðí¶àÍøÕ¾×îÏȽÓÄɶ¯Ì¬ÍøÒ³ÊÖÒÕ¡£¿ÉÊÇ£¬¶¯Ì¬ÍøÒ³µÄURLÍùÍù²»·óÓѺ㬹ØÓÚËÑË÷ÒýÇæµÄÊÕ¼ºÍÓû§·ÖÏí¶¼±£´æÒ»¶¨µÄÄÑÌâ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNginxµÄURLÖØд¹¦Ð§£¬À´ÓÅ»¯ÍøÕ¾µÄ½á¹¹ºÍSEO¡£
Ò»¡¢NginxµÄURLÖØд¹¦Ð§
NginxÊÇÒ»¸ö¸ßÐÔÄܵÄWebЧÀÍÆ÷£¬Ò²ÊÇÒ»¸ö·´ÏòÊðÀíЧÀÍÆ÷¡£Ëü¾ßÓÐÇ¿Ê¢µÄURLÖØд¹¦Ð§£¬¿ÉÒÔ½«Óû§ÇëÇóµÄURL¾ÙÐÐÐ޸ģ¬Ê¹Ö®¸üÇкÏÍøÕ¾µÄ½á¹¹ºÍSEOÐèÇó¡£ÔÚNginxÖУ¬URLÖØд¹¦Ð§ÊÇͨ¹ýrewriteÖ¸Áî¾ÙÐÐÉèÖõġ£
¶þ¡¢URLÖØдÊÃ÷ÈÕ½
¼ÙÉèÎÒÃÇÓÐÒ»¸ö¶¯Ì¬ÍøÒ³£¬URLÀàËÆÓÚ£ºhttp://www.example.com/index.php?id=123¡£ÎÒÃÇÏ£Íû½«Õâ¸öURLÐÞ¸ÄΪ£ºhttp://www.example.com/article/123¡£ÏÂÃæÊǶÔÓ¦µÄNginxÉèÖÃʾÀý£º
server { listen 80; server_name www.example.com; root /var/www/html; location / { if (!-e $request_filename){ rewrite ^/article/(d+)$ /index.php?id=$1 last; break; } } }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬ÎÒÃÇʹÓÃÁËÕýÔò±í´ïʽÀ´Æ¥ÅäURL¡£^/article/(d+)$ÌåÏÖÆ¥ÅäÒÔ/article/¿ªÍ·£¬ºó¸úÒ»¸ö»ò¶à¸öÊý×ÖµÄURL¡£$1ÌåÏÖµÚÒ»¸öÆ¥Åäµ½µÄÊý×Ö¡£
ÔÚlocation¿éÖУ¬Ê×ÏÈͨ¹ýifÖ¸ÁîÅжÏÇëÇóµÄÎļþÊÇ·ñ±£´æ¡£ÈôÊÇÎļþ²»±£´æ£¬Ôò½«URLÖØдΪ/index.php?id=123£¬²¢Ê¹ÓÃlastÖ¸Áî×èֹƥÅ䡣Ȼºó£¬ÇëÇ󽫱»×ª´ï¸øindex.php¾ÙÐд¦Àí¡£
Èý¡¢ÓÅ»¯ÍøÕ¾½á¹¹ºÍSEO
ͨ¹ýURLÖØд£¬ÎÒÃÇ¿ÉÒÔ½«¶¯Ì¬ÍøÒ³µÄURLת»¯Îª¾²Ì¬µÄ¡¢ÓÐÒâÒåµÄURL¡£ÕâÑù×öÓÐÒÔϼ¸¸öÀûÒ棺
ÌáÉýÓû§ÌåÑ飺ÓÐÒâÒåµÄURL¿ÉÒÔ¸üºÃµØÏòÓû§ÐÎòҳÃæÄÚÈÝ£¬Ê¹Óû§¸üÈÝÒ×Ã÷È·ºÍ¼Ç×Å¡£Õâ¿ÉÒÔÌá¸ßÓû§µÄ»á¼ûÌåÑé¡£
ÓÅ»¯ËÑË÷ÒýÇæÊÕ¼£ºËÑË÷ÒýÇæ¸üϲ»¶ÓÐÒâÒåµÄURL£¬ÕâÑùËûÃÇ¿ÉÒÔ¸üºÃµØÃ÷È·ºÍÊÕ¼ÍøÕ¾µÄÄÚÈÝ¡£²¢ÇÒ£¬ÓÐÒâÒåµÄURLÍùÍù°üÀ¨Òªº¦´Ê£¬Õâ¹ØÓÚÍøÕ¾µÄSEOÒ²ÊÇÓÐÒæµÄ¡£
Àû±ã·ÖÏíÁ´½Ó£ºÓÐÒâÒåµÄURL¸üÈÝÒ×·ÖÏí¸øÆäËûÈË£¬ºÃ±Èͨ¹ýÓʼþ»òÉ罻ýÌå¡£Õâ¿ÉÒÔ×ÊÖúÍøÕ¾»ñµÃ¸ü¶àµÄÁ÷Á¿ºÍÆع⡣
ͨ¹ýNginxµÄURLÖØд¹¦Ð§£¬ÎÒÃÇ¿ÉÒÔÇáËɵØʵÏÖ¶Ô¶¯Ì¬ÍøÒ³URLµÄת»¯ºÍÓÅ»¯¡£Õ⽫ÓÐÖúÓÚ¸ÄÉÆÍøÕ¾µÄ½á¹¹ºÍSEO£¬ÌáÉýÓû§ÌåÑéºÍÁ÷Á¿¡£ÔÚÏÖʵӦÓÃÖУ¬ÎÒÃÇ¿ÉÒÔƾ֤ÏêϸÐèÇóºÍ¹æÔò¾ÙÐиüÖØ´óµÄURLÖØдÉèÖá£
½áÂÛ£º
NginxµÄURLÖØд¹¦Ð§ÊÇÓÅ»¯ÍøÕ¾½á¹¹ºÍSEOµÄÖ÷Òª¹¤¾ß¡£Í¨¹ý½«¶¯Ì¬ÍøÒ³µÄURLת»¯Îª¾²Ì¬µÄ¡¢ÓÐÒâÒåµÄURL£¬¿ÉÒÔÌáÉýÓû§ÌåÑ飬ÓÅ»¯ËÑË÷ÒýÇæÊÕ¼£¬Àû±ã·ÖÏíÁ´½Ó¡£Ï£Íû±¾ÎĶÔÄúÃ÷È·NginxµÄURLÖØд¹¦Ð§ºÍÓÅ»¯ÍøÕ¾½á¹¹ÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇNginxÖØдURLÉèÖÃÊÃ÷ÈÕ½£¬ÓÅ»¯ÍøÕ¾½á¹¹ºÍSEOµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡