Ask Your Question
4

The Laravel website cannot be accessed unless /public/ is added to the URL.

asked 2023-05-04 00:12:39 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2023-05-04 00:35:01 +0000

nofretete gravatar image

This issue occurs because Laravel is designed to restrict direct access to files outside the public directory for security reasons. The documents and files that are meant to be accessed by the users should be placed in the public directory, typically found at the root directory of the project.

To access the Laravel website, you need to configure your web server to point to the public directory as the website’s document root. This can be done by creating a virtual host for the website or by modifying the server configuration.

If you are using Apache, you can modify the .htaccess file inside the public directory to enable pretty URLs. Add the following code to the .htaccess file:

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

This code will rewrite all requests to the public directory, allowing you to access your Laravel website without the need to append /public/ to the URL.

Make sure to clear the Laravel application cache after modifying the .htaccess file by running the following command in the terminal:

php artisan config:cache

This should fix the issue and allow you to access your Laravel website without adding /public/ to the URL.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-04 00:12:39 +0000

Seen: 10 times

Last updated: May 04 '23