0

A few days ago I uploaded my laravel project to my hosting with my test domain, in cPanel.

There I could see that my vue components were not loading, I did not see the data tables, etc.. Searching, I compiled the js and css, although the latter was not there and created a build folder in public. I uploaded the project back to hosting, and the vue components are already displayed, but the strange thing is that the API requests do not work, so the components are empty ... For example: I have a table of users, which makes a request to api/userApi, this returns me a 404, however, if I go to route:

myDomain/public/api/usersApi

Because for my project to run, I have to access public, it returns the list of users perfectly. In my .env I have defined this:

APP_URL=https://miDominio.com/public/

I have deleted cache, deleted the bootstrap folder content, deleted cache config... but it doesn't work.

In localhost all run ok

What am I doing wrong?

Update:

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]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    php_value allow_url_fopen On
</IfModule>
4
  • Make sure it does not have any case-sensitive issues. Additionally, Poiting public folder in the APP_URL is not a good practice. Commented Jun 26, 2024 at 16:48
  • @dhruv-pandya thanks for your response. My case sensitive Its ok. In localhost Its ok Commented Jun 26, 2024 at 17:03
  • Then probably it's due to the public folder in the URL. Try changing your root directory by referring to this question: stackoverflow.com/questions/5792153/… Commented Jun 26, 2024 at 17:05
  • @dhruv-pandya i updated my question. I tray with responses in this thread but return 404 error Commented Jun 26, 2024 at 18:05

1 Answer 1

1

Place a .htaccess file on your root within the project directory and add below code to it.

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]

It will redirect your current request to the public folder. This is the same thing that is described in the link that I attached above.

If it doesn't work try the below code.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain-name.com$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /folder/$1 [L]

It works for me when I've same issue with the public folder

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

1 Comment

thanksssssss!!! i understood now and all run in my application!! thanksss

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.