简体   繁体   中英

Why my laravel routes tutorial is not working?

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.

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');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM