skip to Main Content

I have a folder structure like this:

.cpanel/ 
public_html/ 
public_ftp/ 
..

and a laravel project inside the public_html directory like this:

app/
bootstrap/
public/
vendor/
composer.json
artisan
..

The problem was that when I entered the url like www.example.com, it would redirect to www.example.com/public.
I found a rewrite rule that allowed me to put in www.example.com and it would just show public/index.php without the “/public” part:

 RewriteEngine on 
 RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
 RewriteCond %{REQUEST_URI} !^/subfolder/ 
 RewriteCond %{REQUEST_FILENAME} !-f 
 RewriteCond %{REQUEST_FILENAME} !-d 
 RewriteRule ^(.*)$ /subfolder/$1 
 RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
 RewriteRule ^(/)?$ subfolder/index.php [L] 

It worked for the index page, but when I try to go to any of the routes, “/public” shows back up in the URL.

Why does this rewrite rule work for the index page and not for any of the routes? What rewrite rule will work for all of the pages to remove “/public” from the URL?

2

Answers


  1. This should work:

    1. Rename the server.php file in your Laravel root directory to index.php
    2. Copy the .htaccess file from your /public directory to your Laravel root directory.
    Login or Signup to reply.
  2. In your local environment, rename public to public_html

    Copy the project into the parent folder so that the laravel public folder is now the public_html

    .cpanel/
    app/
    bootstrap/
    vendor/
    composer.json
    artisan
    public_html/
    public_ftp/
    ..

    DONT try to fudge it with .htaccess because you will leave your .env file exposed in your server root folder. This is a big security issue if you do.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search