简体   繁体   中英

Laravel - 301 Moved Permanently (from disk cache)

When I navigate to the URL localhost/changecontrol , I expect the index.blade.php to be loaded, instead I get an empty 200 OK response after a 301 Moved Permanently (from disk cache) . The network tab shows this:

changecontrol -> Status Code:301 Moved Permanently (from disk cache)
changecontrol/ -> 200 OK

The browser automatically adds the trailing slash to the URL, presumably because of the weird 301 error. I've tried different browsers and the same thing happens.

I've also tried all the usual cache clears: route:clear , cache:clear , view:clear .

Route

Route::namespace('ChangeControl')->group(function() {
    Route::group(['prefix' => 'changecontrol'], function() {
        Route::get('', 'ChangeController@index');
        ...
    });
});

Controller

public function index()
{
    return view('changecontrol.index');
}

Path to view

views
    changecontrol
        index.blade.php

I have an identical set up for another system which uses exactly the same structure, route setup etc. and that one is working fine.

If I amend the route to Route::get('index', 'ChangeController@index'); and then navigate to changecontrol/index , the view will load as expected.

So I really don't know what's going wrong? Why does it work for one system and not the other?

Okay - after taking a closer look at the web.config :

<match url="^(.*)/$" ignoreCase="false" />
<conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />

This particular rule was causing the issue, because I had a folder where it shouldn't have been:

I had a folder public/changecontrol (which was created mistakenly and never removed). The above rule was matching with this and that's why it was redirecting.

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