简体   繁体   中英

Laravel routes are not working on live server

I just found the problem on server. all is working fine in my localhost, but on live server, ONLY the home page route is working.

My directory is:

laravel-
        css
        js
        local->
             app
                 HTTP->
                      Controllers->
                                Homecontroller
                                 admin->
                                        Groupcontroller   
             config
              ...

Here is my htacess

<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]
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

And my route file is:-

Route::get('/group/detail', 'Groupcontroller@index');
Route::get('/group/add', 'Groupcontroller@create');
Route::get('/group/edit/{id}', 'Groupcontroller@edit');

http://www.example.com/home

My home controller is working.I think issue is with admin folder???

http://www.example.com/admin/group/detail

This is not working

Error is encountered:-

Class App\Http\Controllers\Admin\Groupcontroller does not exist

Please help me,Working fine at localhost but not on live. Thanks in advance

Path of Groupcontroller is Controllers/admin/Groupcontroller . So in your routes you need to access Groupcontroller with appropriate path.

Route::get('/group/detail', 'admin\Groupcontroller@index');
Route::get('/group/add', 'admin\Groupcontroller@create');
Route::get('/group/edit/{id}', 'admin\Groupcontroller@edit');

Also it is recommended to use CamelCase folder names. that is; change admin => Admin.

Try and change the content of your .htacess to this

<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>

Check the namespaces compared to directory names. The cases should match.

Might be you forget to paste .htaccess file from /public folder to /public_html folder

so Just COPY And PASTE the .htaccess file from public folder to /public_html folder

then it will work as local

You can try the bellow code:

After the domain name add "public" keyword between your API routes

for example:-

https://example.com/public/api/someroute

After this, you may have to update your PHP version.

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