簡體   English   中英

Laravel 5中的路由問題

[英]Routing issue in Laravel 5

我在laravel路由中遇到一個奇怪的問題。當我使用CLI工具啟動項目時,一切正常,但是嘗試使用webbrowser會得到NotFoundHttpException 這是我的代碼

路線

Route::get('agent','AgentController@index');

調節器

class AgentController extends Controller {

    //controller for agents 
    public function index(){
        return view('agents/agent-profile');
    }

}

OUTPUT

1.當使用Command php artisan serve --port 8080我可以這樣訪問agent頁面localhost:8080/agent

2.當直接通過localhost/project-folder/public/agent使用webbrowser時,我將收到NotfoundException

我的laravel版本是5.0.31,我正在使用xampp。

htaccess的

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

要刪除index.php,請將以下代碼行復制到公共目錄中的.htaccess文件中:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
#RewriteRule ^(.*)/$ /$1 [L,R=301]


# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

轉到您的xampp控制面板-> Apache->配置->打開httpd.conf

找到這條線

LoadModule rewrite_module modules/mod_rewrite.so

取消注釋

完成

將您的Web服務器上的public文件夾而不是project-folder

刪除網址中的公共網址。 您只能使用“ localhost / project-folder / agent”,因為根目錄始終指向“ public”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM