laravel5Ôõôȥµôindex.php
laravelÊÇÒ»¿îÊ¢ÐеÄphp¿ò¼Ü£¬ËüÌṩÁËÐí¶à±ãµ±µÄ¹¦Ð§ºÍÇ¿Ê¢µÄÐÔÄÜ£¬ÒÔ×ÊÖú¿ª·¢Ö°Ô±¿ìËÙ¹¹½¨¸ßÖÊÁ¿µÄwebÓ¦ÓóÌÐò¡£È»¶ø£¬ÓÉÓÚĬÈÏÇéÐÎÏÂlaravel¿ò¼ÜʹÓÃÁË´øÓÐindex.phpµÄurl£¬Õâ¿ÉÄÜ»á¶ÔseoºÍÓû§ÌåÑéÔì³É²»Á¼Ó°Ïì¡£±¾ÎĽ«ÏÈÈÝÔõÑùÈ¥µôlaravel5ÖеÄindex.php¡£
ÔÚLaravel5ÖУ¬È¥µôindex.phpµÄÒªÁìÓÐÁ½ÖÖ¡£µÚÒ»ÖÖÒªÁìÊÇͨ¹ý.htaccessÎļþ¾ÙÐÐÉèÖ㬵ڶþÖÖÒªÁìÊÇͨ¹ýÐÞ¸ÄLaravelÉèÖÃÎļþ¾ÙÐÐÉèÖ᣽ÓÏÂÀ´£¬ÎÒÃǽ«ÖðÒ»ÏÈÈÝÕâÁ½ÖÖÒªÁì¡£
1¡¢Í¨¹ý.htaccessÎļþ¾ÙÐÐÉèÖÃ
.htaccessÎļþÊÇÓÃÀ´ÉèÖÃApache WebЧÀÍÆ÷µÄÎļþ¡£Í¨¹ýÐÞ¸Ä.htaccessÎļþ£¬ÎÒÃÇ¿ÉÒÔÖ±½ÓÈ¥µôLaravel5ÖеÄindex.php¡£ÏÂÃæÊÇÏêϸµÄÉèÖð취£º
1.1¡¢ÕÒµ½Laravel5ÏîÄ¿µÄ¸ùĿ¼
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÕÒµ½´æ·ÅLaravel5ÏîÄ¿µÄ¸ùĿ¼¡£ÈôÊÇÄúÊÇÔÚÍâµØ´î½¨µÄ¿ª·¢ÇéÐΣ¬Ôòͨ³£´æ·ÅÔÚWebЧÀÍÆ÷¸ùĿ¼Ï¡£ÈôÊÇÄúÊÇͨ¹ýFTPµÈ¹¤¾ß½«ÏîÄ¿ÉÏ´«µ½Ô¶³ÌЧÀÍÆ÷£¬ÔòÐèÒªÕÒµ½ÄúÉÏ´«µÄĿ¼¡£
1.2¡¢½¨Éè.htaccessÎļþ
ÔÚÉÏÒ»²½ÕÒµ½µÄĿ¼ÖУ¬½¨ÉèÒ»¸öÃûΪ.htaccessµÄÎļþ£¬²¢½«ÒÔÏ´úÂ븴ÖƵ½ÎļþÖУº
<ifmodule> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </ifmodule>
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëµÄ¼ÄÒåÊÇ£ºÈôÊÇWebЧÀÍÆ÷ÉÏ×°ÖÃÁËmod_rewriteÄ£¿é£¬ÔòÆôÓÃRewriteEngine£¬½«URLÖض¨Ïòµ½publicĿ¼Ï¡£ÕâÑù£¬»á¼ûLaravel5ÏîĿʱ¾Í¿ÉÒÔÖ±½ÓÈ¥µôindex.phpÁË¡£
1.3¡¢ÐÞ¸ÄApacheÉèÖÃÎļþ
ÔÚÈ·±£Ð§ÀÍÆ÷ÉÏ×°ÖÃÁËmod_rewriteÄ£¿éÖ®ºó£¬»¹ÐèÒªÐÞ¸ÄApacheµÄÉèÖÃÎļþ£¬ÒÔÈ·±£.htaccessÎļþ¿ÉÒÔÊ©Õ¹×÷Ó᣷¿ªApacheÉèÖÃÎļþ£¨Ò»Ñùƽ³£´æ·ÅÔÚ/etc/httpd/conf/httpd.confÖУ©£¬ÕÒµ½ÈçÏÂÉèÖãº
<directory> AllowOverride None ... </directory>
µÇ¼ºó¸´ÖÆ
½«ÆäÖеġ°AllowOverride None¡±ÐÞ¸ÄΪ¡°AllowOverride All¡±¡£Ð޸ĺóµÄÉèÖÃÈçÏ£º
<directory> AllowOverride All ... </directory>
µÇ¼ºó¸´ÖÆ
1.4¡¢ÖØÆôApacheЧÀÍÆ÷
ÐÞ¸ÄÍêApacheÉèÖÃÎļþÖ®ºó£¬ÐèÒªÖØÆôApacheЧÀÍÆ÷£¬ÒÔʹеÄÉèÖÃÉúЧ¡£ÏêϸÏÂÁîÈçÏ£º
sudo service httpd restart
µÇ¼ºó¸´ÖÆ
2¡¢Í¨¹ýÐÞ¸ÄLaravelÉèÖÃÎļþ¾ÙÐÐÉèÖÃ
ÈôÊÇÄú¶ÔApacheµÄÏà¹ØÉèÖò»Ïàʶ£¬»òÕßÎÞ·¨Ö±½ÓÐÞ¸ÄЧÀÍÆ÷ÉèÖÃÎļþ£¬Ôò¿ÉÒÔͨ¹ýÐÞ¸ÄLaravelÉèÖÃÎļþÍù¸´µôindex.php¡£ÏÂÃæÊÇÏêϸµÄÉèÖð취£º
2.1¡¢·¿ªLaravelÉèÖÃÎļþ
Ê×ÏÈ£¬ÕÒµ½´æ·ÅLaravel5ÏîÄ¿µÄ¸ùĿ¼£¬È»ºó½øÈëµ½¡°config¡±Ä¿Â¼Ï£¬ÕÒµ½ÃûΪ¡°app.php¡±µÄÉèÖÃÎļþ¡£
2.2¡¢ÐÞ¸ÄÉèÖÃÎļþ
ÔÚ¡°app.php¡±ÎļþÖУ¬ÕÒµ½ÒÔÏÂÁ½ÐдúÂ룺
'index' => 'index.php', ... 'url' => 'http://localhost',
µÇ¼ºó¸´ÖÆ
½«¡°index.php¡±ÐÞ¸ÄΪ¿Õ×Ö·û´®£¬Ð޸ĺóµÄ´úÂëÈçÏ£º
'index' => '', ... 'url' => 'http://localhost',
µÇ¼ºó¸´ÖÆ
ÕâÑù£¬»á¼ûLaravel5ÏîĿʱ¾Í¿ÉÒÔÖ±½ÓÈ¥µôindex.phpÁË¡£
ÐèҪעÖصÄÊÇ£¬ÈôÊÇÄúµÄLaravelÏîÄ¿°²ÅÅÔÚ×ÓĿ¼Ï£¬ÔòÐèÒª½«¡°url¡±Ñ¡ÏîÐÞ¸ÄΪ¡°http://localhost/your_sub_folder¡±£¬ÆäÖС°your_sub_folder¡±ÎªÄúµÄ×ÓĿ¼Ãû³Æ¡£
×ܽ᣺
±¾ÎÄÏÈÈÝÁËÁ½ÖÖÒªÁ죬¿ÉÒÔÈ¥µôLaravel5ÖеÄindex.php¡£µÚÒ»ÖÖÒªÁìÐèÒªÔÚApacheÉèÖÃÎļþÖоÙÐÐÐ޸ģ¬ÊʺÏÓÚÓÐЧÀÍÆ÷ÖÎÀíÂÄÀúµÄÓû§£»µÚ¶þÖÖ·½¹æÔòÔ½·¢¼òÆÓ£¬Í¨¹ýÐÞ¸ÄLaravelÉèÖÃÎļþ¼´¿ÉʵÏÖ¡£ÎÞÂÛÄúÑ¡ÔñÄÄÖÖÒªÁ죬¶¼¿ÉÒÔÈÃÄúµÄLaravel5ÏîÄ¿Ô½·¢ÓѺã¬Ìá¸ßÓû§ÌåÑéºÍSEOЧ¹û¡£
ÒÔÉϾÍÊÇlaravel5Ôõôȥµôindex.phpµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡