# Serve Laravel from the public directory
Source: https://docs.webgee.com/en/development/laravel-public-directory



Make `example.com` serve your Laravel application without `/public` in the URL.
Applies to shared, reseller and Premium hosting.

Laravel expects only its `public` directory to be web-accessible. On shared
hosting you usually cannot change the document root, so a rewrite rule does the
same job.

<Callout type="warn">
  This matters for security, not just tidiness. If the whole Laravel directory
  is web-accessible, `.env` — which holds your database password and application
  key — can be requested directly over HTTP.
</Callout>

## Add the rewrite [#add-the-rewrite]

1. In cPanel, open **File Manager** and go to `public_html`.

2. Enable &#x2A;*Settings → Show Hidden Files (dotfiles)**, since `.htaccess` is
   hidden by default.

3. Open `.htaccess`, or create it if it does not exist.

4. Add this at the **top** of the file:

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

5. Save.

## Check it worked [#check-it-worked]

Visit `https://example.com`. Your application should load, without `/public` in
the address.

Then confirm the file that matters is not reachable:

```bash
curl -sI https://example.com/.env | head -n 1
```

You want `403` or `404`. A `200` means `.env` is being served — stop and fix
that before going further.

## A better option if you have it [#a-better-option-if-you-have-it]

On a VPS or dedicated server, set the document root to the `public` directory
directly in WHM rather than rewriting. It is one less moving part, and nothing
above `public` is exposed at all.

## If it does not work [#if-it-does-not-work]

* **A redirect loop** — there is another `RewriteRule` above this one. The
  Laravel rule must come first.
* **The old URL is cached** — clear your browser cache, or test in a private
  window.
* **A 500 error** — check `error_log` in `public_html`. See
  [Find your error log](/en/development/how-do-i-find-my-error-log-file-to-find-errors-for-my-php-application).

## Related [#related]

* [Enable directory index listings using .htaccess](/en/hosting/enable-directory-index-listings-using-htaccess)
* [Find your error log](/en/development/how-do-i-find-my-error-log-file-to-find-errors-for-my-php-application)
