nginxÔõôα¾²Ì¬
nginx α¾²Ì¬ÉèÖÃ
α¾²Ì¬ÊÇÖ¸½«¶¯Ì¬Íøַת»»Îª¾²Ì¬ÍøÖ·£¬´Ó¶øÌá¸ßÍøÕ¾Çå¾²ÐÔ²¢¸ÄÉÆÓû§ÌåÑé¡£Nginx ÖпÉÒÔͨ¹ýÒÔÏ°취ÉèÖÃα¾²Ì¬£º
1. ÆôÓÃα¾²Ì¬Ä£¿é
ÔÚ Nginx ÉèÖÃÎļþÖУ¬ÕÒµ½ http{} ¿é£¬²¢ÔÚÆäÖÐÌí¼ÓÒÔÏÂÐУº
load_module rewrite_module modules/mod_rewrite.so;
µÇ¼ºó¸´ÖÆ
2. ½ç˵α¾²Ì¬¹æÔò
ÔÚ http{} ¿éÄÚ£¬Ìí¼ÓÒÔÏÂα¾²Ì¬¹æÔò£º
rewrite ^/(.+) /index.php?q=$1 last;
µÇ¼ºó¸´ÖÆ
´Ë¹æÔò½«½«ËùÓж¯Ì¬ URL£¨ÒÔ / ¿ªÍ·£©ÖØдΪ¾²Ì¬ URL£¨/index.php£©£¬²¢½«¶¯Ì¬²¿·Ö×÷Ϊ q ²ÎÊýת´ï¡£
3. ´¦ÀíÅÌÎÊ×Ö·û´®
ÔÚ index.php ÎļþÖУ¬Ê¹ÓÃÒÔÏ´úÂë´¦ÀíÅÌÎÊ×Ö·û´®£º
<?php $query = $_GET['q']; // ´¦Àí¶¯Ì¬ÄÚÈÝ ?>
µÇ¼ºó¸´ÖÆ
4. ʾÀý
ÀýÈ磬ÈôÊÇÓÐÒ»¸ö¶¯Ì¬ URL /articles/10£¬ÖØдºó½«±äΪ /index.php?q=articles/10¡£index.php ½«ÎüÊÕ q ²ÎÊýΪ articles/10£¬²¢ÏÔʾÏìÓ¦µÄÎÄÕ¡£
ÀûÒæ
α¾²Ì¬ÉèÖÃÌṩÁËÒÔÏÂÀûÒ棺
Ìá¸ßÇå¾²ÐÔ£ºÒþ²Ø¶¯Ì¬ÍøÖ·£¬½µµÍ±»¹¥»÷µÄΣº¦¡£
¸ÄÉÆÓû§ÌåÑ飺¾²Ì¬ÍøÖ·¸üÒ×ÓÚ¼ÇןͷÖÏí¡£
Ìá¸ßËÑË÷ÒýÇæÓÅ»¯£¨SEO£©£ºËÑË÷ÒýÇæÇãÏòÓÚ¾²Ì¬ÍøÖ·¡£
ÒÔÉϾÍÊÇnginxÔõôα¾²Ì¬µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡