2

why my laravel url not working when method is post example the url api must be : http://localhost/PROJECTNAME/api/loginWeb

but when i click post button it always direct to http://localhost/api/loginWeb

but when method is get this okay. i use xampp

here is my 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]

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

5
  • in .env set APP_URL= Commented Sep 17, 2020 at 6:45
  • yes, already set APP_URL=localhost or APP_URL=localhost/PROJECTFOLDER but still not working Commented Sep 17, 2020 at 6:53
  • how you are testing that url is not working? Commented Sep 17, 2020 at 6:55
  • i am using api for login , so i just check the inspect element, the url always direct to localhost/api instead localhost/projectfolder/api Commented Sep 17, 2020 at 7:01
  • you are using vuejs .? or ajax Commented Sep 17, 2020 at 7:03

1 Answer 1

0

When we're using session based laravel setup, all the route generator functions(url(), route()) use hostname http://localhost as root url, not http://localhost/PROJECTNAME. To resolve this issue please do following changes in laravel app.

  • Define APP_URL in .env file as APP_URL="http://localhost/PROJECTNAME"
  • Go to RouteServiceProvider which is located at app/Providers/RouteServiceProvider and force laravel to use APP_URL as root url for your app.
public function boot()
{
    parent::boot();
    // Add following lines to force laravel to use APP_URL as root url for the app.
    $strBaseURL = $this->app['url'];
    $strBaseURL->forceRootUrl(config('app.url'));
}

Same issue occurred to me when I used same domain and a suburl to identify different projects.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.