B L Praveen
B L Praveen

Reputation: 1990

"403 Forbidden You don't have permission to access" in the laravel

All ajax request are failing with 403 Forbidden error. Is it due to htaccess. I am having this issue after hosting it on the server.I have changed the .htaccess as below.

<IfModule mod_rewrite.c>
AddHandler application/x-httpd-php72 .php
    RewriteEngine On
    # Removes index.php from ExpressionEngine URLs  
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

</IfModule>

I am having public files in public_html and other folders on the root directory.

I am having the files in the path API\MyContorller and the route Route::apiResources(['post' => 'API\MyContorller ]);

I am having this issue with XHR Request i.e Ajax Call Put Request

I am calling update method to update the table in the vue Component

updateQuiz(){
    this.form.put('/api/chapter/'+this.$route.params.id + '/quiz/' + this.form.id);
}

Upvotes: 1

Views: 15736

Answers (4)

Milosz
Milosz

Reputation: 21

Remember about CSRF token in requests.

If you're using PUT/DELETE method, you can transform this to

{
    method: 'POST',
    data: { _method: 'PUT', _token: token },
}

Upvotes: 2

Kojo Yeboah
Kojo Yeboah

Reputation: 1

I had a similar problem, it turns out not doing git init before is the actual cause of this problem. It doesn't matter if you have already hooked the project to a GitHub repository. Make sure u do a git init at the beginning and then do a git add . before u commit and push

Upvotes: 0

B L Praveen
B L Praveen

Reputation: 1990

If anybody get into this trouble . Here is the solution add below code to your htaccess file in the public folder

<Limit GET POST PUT OPTIONS>
    Require all granted
</Limit>
<LimitExcept GET POST PUT OPTIONS>
    Require all denied
</LimitExcept>

Upvotes: 1

Milosz
Milosz

Reputation: 21

If you are using hosting which have web server mapping to root directory, your htaccess file should contains request redirect to public/index.php file e.g.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

Upvotes: 0

Related Questions