laravelµÄappurlÓÐʲôÓÃ
laravelÊÇÒ»¸ö¿ªÔ´µÄphp¿ò¼Ü£¬Ëü¾ßÓмòÆÓ¡¢ÓÅÑÅ¡¢¸ßЧµÄÌص㣬±»ÆÕ±éÓ¦ÓÃÓÚweb¿ª·¢¡£ÔÚlaravelÖУ¬app_urlÊÇÒ»¸öºÜÊÇÖ÷ÒªµÄÉèÖÃÑ¡ÏËü¿ÉÒÔÓ°Ïìµ½ÍøÕ¾µÄÁ´½ÓÌìÉú¡¢Óʼþ·¢ËÍ¡¢¹ýʧ±¨¸æµÈ¶à¸ö·½Ãæ¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÉîÈë̽ÌÖlaravelµÄapp_url£¬Ì½ÌÖËüµÄ×÷ÓúÍÓ÷¨¡£
Ò»¡¢app_urlµÄ×÷ÓÃ
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÃ÷È·LaravelÖеÄapp_url¾¿¾¹ÊÇʲô¡£app_urlÊÇLaravelµÄÒ»¸öÉèÖÃÑ¡ÏËü¿ÉÒÔÖ¸¶¨Ó¦ÓóÌÐòµÄURLµØµã¡£ÔÚLaravelÖУ¬Ðí¶à¹¦Ð§¶¼ÐèҪʹÓÃURLµØµã£¬ºÃ±È·ÓÉ¡¢Öض¨Ïò¡¢Á´½ÓÌìÉú¡¢Óʼþ·¢Ë͵ȵȡ£Õâʱ£¬Laravel¾Í»áƾ֤app_urlÀ´ÌìÉú¶ÔÓ¦µÄURLµØµã¡£
ÏêϸÀ´Ëµ£¬app_url¶ÔLaravelµÄ×÷ÓÃÖ÷ÒªÓÐÒÔϼ¸¸ö·½Ã棺
1¡¢Â·ÓÉ£ºÔÚ½ç˵·ÓÉʱ£¬ÈôÊÇÐèÒªÖ¸¶¨URLµØµã£¬Laravel¾Í»áÓÃapp_urlÀ´ÌìÉú¶ÔÓ¦µÄURLµØµã¡£ºÃ±ÈÏÂÃæÕâ¸öÀý×Ó£º
Route::get('/home', 'HomeController@index')->name('home');
µÇ¼ºó¸´ÖÆ
µ±ÎÒÃÇʹÓÃroute()º¯ÊýÀ´ÌìÉú/home·ÓɵÄURLÁ´½Óʱ£¬Laravel¾Í»áʹÓÃapp_urlÀ´ÌìÉúÍêÕûµÄÁ´½ÓµØµã¡£
2¡¢Öض¨Ïò£ºÔÚʹÓÃLaravelµÄÖض¨Ïò¹¦Ð§Ê±£¬ÐèÒªÖ¸¶¨Öض¨ÏòµÄURLµØµã¡£´Ëʱ£¬Laravel»áʹÓÃapp_urlÀ´ÌìÉú¶ÔÓ¦µÄURLµØµã¡£ºÃ±ÈÏÂÃæÕâ¸öÀý×Ó£º
return redirect('/home');
µÇ¼ºó¸´ÖÆ
µ±ÎÒÃÇÖ´ÐÐÕâ¸öÖض¨Ïò²Ù×÷ʱ£¬Laravel¾Í»áʹÓÃapp_urlÀ´ÌìÉúÍêÕûµÄ/homeÁ´½ÓµØµã¡£
3¡¢Á´½ÓÌìÉú£ºÔÚLaravelÖУ¬¾³£ÐèÒªÌìÉúÖÖÖÖÁ´½Ó£¬ºÃ±ÈÕ¾ÄÚÁ´½Ó¡¢Õ¾ÍâÁ´½Ó¡¢¾²Ì¬×ÊÔ´Á´½ÓµÈµÈ¡£´Ëʱ£¬Laravel¾Í»áʹÓÃapp_urlÀ´ÌìÉú¶ÔÓ¦µÄÍêÕûÁ´½ÓµØµã¡£
4¡¢Óʼþ·¢ËÍ£ºÔÚʹÓÃLaravelµÄÓʼþ·¢Ë͹¦Ð§Ê±£¬ÐèÒªÖ¸¶¨ÓʼþÖеÄÁ´½ÓµØµã¡£´Ëʱ£¬LaravelÒ²»áʹÓÃapp_urlÀ´ÌìÉú¶ÔÓ¦µÄÁ´½ÓµØµã¡£
5¡¢¹ýʧ±¨¸æ£ºÔÚLaravelÖУ¬ÈôÊÇ·ºÆðÁË䲶»ñµÄÒì³££¬ÏµÍ³¾Í»á½«¹ýʧÐÅÏ¢ÏÔʾÔÚÍøÒ³ÉÏ¡£´Ëʱ£¬ÏµÍ³Ò²»áʹÓÃapp_urlÀ´ÌìÉú¶ÔÓ¦µÄ¹ýʧ±¨¸æÁ´½ÓµØµã¡£
ÓÉÉÏÊöÄÚÈÝ¿ÉÖª£¬app_urlÔÚLaravelÖÐÆðµ½ÁËÖÁ¹ØÖ÷ÒªµÄ×÷Óá£Ëü²»µ«Ó°Ïìµ½LaravelµÄ·ÓÉ¡¢Á´½ÓÌìÉú¡¢Óʼþ·¢Ë͵ȶà¸ö¹¦Ð§£¬»¹¿ÉÒÔʹ×ðÁú¿Ê±³ÌÐòÔ½·¢½áʵºÍ¿ÉÀ©Õ¹¡£
¶þ¡¢app_urlµÄÓ÷¨
ÔÚLaravelÖУ¬ÎÒÃÇ¿ÉÒÔʹÓöàÖÖÒªÁìÀ´ÉèÖÃapp_url¡£ÏÂÃæ»®·ÖÏÈÈÝÔõÑùÔÚÉèÖÃÎļþ¡¢ÇéÐαäÁ¿ºÍ³ÌÐò´úÂëÖÐÉèÖÃapp_url¡£
1¡¢ÔÚÉèÖÃÎļþÖÐÉèÖÃapp_url
ÔÚLaravelµÄÉèÖÃÎļþÖУ¬¿ÉÒÔͨ¹ýAPP_URLÑ¡ÏîÀ´ÉèÖÃapp_url¡£APP_URLÑ¡ÏîÔÚconfig/app.phpÎļþÖУ¬Ò»Ñùƽ³£ÊÇÔÚÎļþµ×²¿µÄ¡°ÇéÐαäÁ¿¡±ÇøÓòÖС£
ÔÚAPP_URLÑ¡ÏîÖУ¬ÎÒÃÇ¿ÉÒÔÌîдĿ½ñÓ¦ÓóÌÐòµÄURLµØµã£¬ÀýÈ磺
'APP_URL' => 'http://example.com',
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«app_urlÉèÖÃΪhttp://example.com¡£µ±LaravelÐèÒªÌìÉúÁ´½Óʱ£¬¾Í»áʹÓÃÕâ¸öURLµØµã×÷Ϊǰ׺¡£
2¡¢ÔÚÇéÐαäÁ¿ÖÐÉèÖÃapp_url
ÔÚÏÖʵÉú²úÇéÐÎÖУ¬ÎÒÃǾ³£ÐèÒªÔÚ²î±ðµÄЧÀÍÆ÷ÉÏ°²ÅÅÓ¦ÓóÌÐò¡£Õâʱ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÇéÐαäÁ¿À´ÉèÖÃapp_url£¬ÒÔÊÊÅä²î±ðµÄЧÀÍÆ÷ºÍÓòÃû¡£
ΪÁËÉèÖÃÇéÐαäÁ¿£¬ÎÒÃÇÐèÒªÔÚЧÀÍÆ÷ÉϽ¨ÉèÒ»¸ö.envÎļþ£¬È»ºó½«APP_URLÑ¡Ïî¼ÓÈëµ½Õâ¸öÎļþÖС£ÀýÈ磺
APP_URL=http://example.com
µÇ¼ºó¸´ÖÆ
ÕâÑù¾Í¿ÉÒÔÔÚ²î±ðЧÀÍÆ÷ÉÏÉèÖòî±ðµÄAPP_URLÑ¡ÏÒÔ˳Ӧ²î±ðµÄÓòÃûºÍÐÒé¡£
3¡¢ÔÚ³ÌÐò´úÂëÖÐÉèÖÃapp_url
ÔÚijЩÇéÐÎÏ£¬ÎÒÃÇ¿ÉÄÜÐèÒªÔÚ³ÌÐò´úÂëÖж¯Ì¬ÉèÖÃapp_url¡£ÀýÈ磬µ±ÎÒÃÇÐèÒª·¢ËÍÍøÕ¾ÑéÖ¤Óʼþʱ£¬¾ÍÐèÒªÔÚURLÖаüÀ¨Ä¿½ñÓû§µÄIDÐÅÏ¢¡£Õâʱ£¬ÎÒÃÇ¿ÉÒÔͨ¹ý´úÂëÀ´ÉèÖÃapp_url¡£
ÔÚLaravelÖУ¬ÉèÖÃapp_urlµÄ´úÂëºÜÊǼòÆÓ¡£Ö»ÐèҪʹÓÃconfig()º¯Êý¼´¿É¡£ÀýÈ磬ÏÂÃæÕâ¸öÀý×ӾͶ¯Ì¬ÉèÖÃÁËapp_url£º
$url = config('app.url'); config(['app.url' => $url . '/user/' . $userId]);
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬Ê×ÏÈʹÓÃconfig()º¯Êý»ñÈ¡Ä¿½ñµÄapp_url£¬È»ºóͨ¹ý×Ö·û´®Æ´½ÓµÄ·½·¨¶¯Ì¬ÌìÉúеÄURLµØµã£¬²¢Ê¹ÓÃconfig()º¯Êý¸üÐÂapp_urlµÄÖµ¡£
×ܽá
±¾ÎÄÉîÈë̽ÌÖÁËLaravelÖеÄapp_url£¬ÐðÊöÁËËü¹ØÓÚLaravel·ÓÉ¡¢Öض¨Ïò¡¢Á´½ÓÌìÉú¡¢Óʼþ·¢ËÍ¡¢¹ýʧ±¨¸æµÈ¶à¸ö¹¦Ð§µÄÓ°Ï졣ͬʱ£¬±¾ÎÄ»¹ÏÈÈÝÁËÔÚLaravelÖÐÔõÑùÉèÖÃapp_url£¬°üÀ¨ÔÚÉèÖÃÎļþ¡¢ÇéÐαäÁ¿ºÍ³ÌÐò´úÂëÖÐÉèÖá£Ï£Íû¶ÁÕßͨ¹ý±¾ÎĵÄѧϰ£¬Äܹ»¸üºÃµØÕÆÎÕLaravelÖеÄapp_url£¬Îª¸üºÃµÄ³ÌÐòÉè¼ÆºÍ¿ª·¢µÓÚ¨»ù´¡¡£
ÒÔÉϾÍÊÇlaravelµÄappurlÓÐʲôÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡