0

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?

ajw4sk
  • 95
  • 2
  • 13

2 Answers2

0

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.

Snapey
  • 3,604
  • 1
  • 21
  • 19
  • This would be a good cpanel-specific answer for the (updated) dupe target. I'm trying to remove as many links as I can to the previous target, which has 2 dozen bad answers. – miken32 Jun 12 '23 at 15:22
-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.