dongzine3782 2018-02-05 13:22 采纳率: 0%
浏览 47
已采纳

为什么我的laravel路线教程不起作用?

I m noob at php based web development, I'm trying a Laravel from scratch tutorial.

First I had an issue with the .dev that I fixed in laragon preferences using a .mc that will not forces https.

My link is http://localhost/e-commerce-tutorial/public/ for the welcome page

Now I m trying to create a routing scenario

I did put an about.blade.php page in : resources/views/pages

Then I edited the laravel wellcome page adding this link to the menu :

           <a href="{{ url('/about') }}">About</a>

finally my web.php

Route::get('/', function () {
    return view('welcome');
});

Route::any(
        '/about', 
        function (){
            return view('pages.about');
        }
 );

I did some research but no success:

I tried this two .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>

OR

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

        RewriteEngine On

        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} (.+)/$
        RewriteRule ^ %1 [L,R=301]

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

My browser response is :

Not Found The requested URL /e-commerce-tutorial/public/about was not

found on this server.

  • 写回答

1条回答 默认 最新

  • doubu1970 2018-02-05 13:27
    关注

    Try this .htaccess file

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
    
        RewriteEngine On
        #RewriteBase /~projectname/master/
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/$ /$1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    </IfModule>
    

    Also Please try this

    Route::get('/about', function () {
        return view('pages.about');
    });
    
    Route::post('/about', function () {
        return view('pages.about');
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?