thinkphp5α¾²Ì¬Ôõôд
thinkphpÊÇÒ»¸öÓÅÒìµÄphp¿ª·¢¿ò¼Ü£¬Ê¹ÓÃËü¿ÉÒÔ×ÊÖú¿ª·¢ÕßÌá¸ß¿ª·¢Ð§ÂÊ£¬ïÔÌÏîÄ¿¿ª·¢ºÍά»¤±¾Ç®¡£¶øα¾²Ì¬µÄʹÓÃÔòÊÇÒ»ÖÖÌá¸ßÍøÕ¾»á¼ûÐÔÄܵÄÊÖÒÕÊֶΣ¬Ëü¿ÉÒÔͨ¹ý½«¶¯Ì¬Ò³ÃæµÄÁ´½Óת»¯Îª¾²Ì¬Á´½ÓµÄÐÎʽÀ´Ìá¸ßÍøÕ¾»á¼ûËÙÂÊ£¬ÌáÉýÓû§ÌåÑé¡£±¾ÎĽ«½²ÊöÔõÑùÔÚthinkphp5ÖÐÉèÖÃα¾²Ì¬¡£
Ê×ÏÈ£¬ÐèÒªÔÚÓ¦ÓóÌÐòµÄ¸ùĿ¼Ï½¨Éè.htaccessÎļþ£¬×¢ÖØÎļþÃûÇ°ÃæÓÐÒ»¸öСÊýµã£¬ÕâÊÇÒþ²ØÎļþµÄÃüÃû·½·¨¡£¸ÃÎļþ±ØÐèÓпÉдȨÏÞ£¬²»È»ÎÞ·¨¾ÙÐÐÎļþ¶Áд²Ù×÷¡£
ÒÔÏÂÊÇ.htaccessÎļþµÄÄÚÈÝʾÀý£¬¸ÃʾÀý¿ÉÒÔ½«°üÀ¨index.phpµÄURLµØµãת»»Îª²»º¬index.phpµÄURLµØµã£¬²¢È¥µôºó׺Ãû¡£
<ifmodule> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)\.(html|htm|php)$ /index.php/$1 [L] </ifmodule>
µÇ¼ºó¸´ÖÆ
RewriteEngine On£ºÌåÏÖÆôÓÃÖØдÒýÇæ¡£
RewriteBase /£ºÌåÏÖ¹æÔòµÄ»ù´¡Ä¿Â¼Â·¾¶¡£
RewriteCond %{REQUEST_FILENAME} !-d£ºÌåÏÖÈôÊÇÇëÇóµÄ²»ÊÇĿ¼£¬ÔòÖ´ÐкóÃæµÄ¹æÔò¡£
RewriteCond %{REQUEST_FILENAME} !-f£ºÌåÏÖÈôÊÇÇëÇóµÄ²»ÊÇÎļþ£¬ÔòÖ´ÐкóÃæµÄ¹æÔò¡£
RewriteRule ^(.).(html|htm|php)$ /index.php/$1 [L]£ºÌåÏÖ½«°üÀ¨.html¡¢.htm¡¢.phpºó׺ÃûµÄURLµØµãÖØдΪ/index.php/¿ªÍ·µÄURLµØµã£¬²¢È¥µôºó׺Ãû¡£ÆäÖУ¬$1ÌåÏÖµÚÒ»¸ö²¶»ñ×飬¼´(.)Ëù±í´ïµÄí§Òâ×Ö·ûÐòÁС£
Íê³É.htaccessÎļþµÄÉèÖú󣬻¹ÐèÒªÔÚThinkPHP5µÄ¿ò¼ÜÉèÖÃÎļþÖоÙÐÐÉèÖ᣷¿ªconfigĿ¼ÏµÄapp.phpÎļþ£¬ÔÚurl_route_onÉèÖÃÏîÏÂÌí¼ÓÈçÏ´úÂ룺
'url_route_rules' => [ // ÈôÊÇÖ»ÓÐÀο¿µÄµØµãÐèҪα¾²Ì¬£¬Ôòƾ֤ÒÔÏ·½·¨ÉèÖà 'static' => 'index/index/static', // ÈôÊÇÐèÒª¶à¸öα¾²Ì¬£¬ÔòʹÓÃÕýÔò±í´ïʽÀ´ÉèÖà 'static/:id' => 'index/index/static?id=:1', ],
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬µÚÒ»¸öÉèÖÃÏîΪÀο¿µØµãµÄα¾²Ì¬ÉèÖᣵڶþ¸öÉèÖÃÏîÔòÐèÒªÕýÔò±í´ïʽÀ´ÊµÏÖ¶¯Ì¬²ÎÊýµÄת»¯¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
×îºó£¬ÎªÈ·±£ÉèÖÃÉúЧ£¬»¹ÐèÒªÔÚЧÀÍÆ÷ÇéÐÎÖпªÆôApacheµÄrewriteÄ£¿é¡£ÔÚApacheÉèÖÃÎļþhttpd.confÖÐÕÒµ½¸ÃÄ£¿éµÄÉèÖÃÏ½«Æä×÷·Ï×¢Êͼ´¿ÉÆôÓá£
Íê³ÉÒÔÉÏÉèÖúó£¬Î±¾²Ì¬¹¦Ð§¼´¿ÉÔÚThinkPHP5ÖÐÕý³£Ê¹Óá£Í¨¹ýα¾²Ì¬µÄ·½·¨£¬¿ÉÒÔʵÏÖ¸üºÃµÄSEOЧ¹ûºÍ¸ü¿ìµÄ»á¼ûËÙÂÊ£¬´Ó¶øÌáÉýÍøÕ¾µÄÓû§ÌåÑé¡£
ÒÔÉϾÍÊÇthinkphp5α¾²Ì¬ÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡