Takhtak Team
Takhtak Team

Reputation: 141

how to run Laravel API on line server

I have created Laravel CRUD API and it works fine in localhost(without .htaccess file), but it fails on the live server. When I send a request it returns 404 not found error, or downloads a file depending on .htaccess content. How should I change .htaccsess file for makeing code to work. this is my .htaccess file which returns not found error.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Upvotes: 0

Views: 381

Answers (1)

Flame
Flame

Reputation: 7580

There is an 'official' htaccess that should provide you with the basic code to get this working.

See https://github.com/laravel/laravel/blob/master/public/.htaccess

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

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

Then, simply make sure that the root points to yourproject/public so it can boot only from yourproject/public/index.php.

Upvotes: 1

Related Questions