0

I have hosted Laravel 8 application in sub folder

Inside public_html folder have created subfolder with project_name

and when i access it

https://maindomain.in/project_name

it

redirects to https://maindomain.in/public/project_name

I have checked these links

  1. Laravel 7.x - How to remove 'public' from URL?
  2. Remove public from URL Laravel 5.3 on shared hosting

tried changing .htaccess and renaming server.php to index.php but can only access site through

https://maindomain.in/project_name/public this url.

It only reads .htaccess of public directory.

htaccess of root directory

Options -MultiViews -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

Any solution. Thanks

user3653474
  • 3,393
  • 6
  • 49
  • 135
  • I have an answer in a post with mainly the same issue, many people tried my structure and worked for them, checking this post can help: https://stackoverflow.com/a/71387680/16101788 it talks about structuring a laravel project in a server. In any case, the public folder was added to the url. – Guille Apr 09 '22 at 12:50
  • @Guille Thanks will placing `index.php` file inside public folder will cause issue? i have already one `index.php` file for other application inside public_html folder – user3653474 Apr 09 '22 at 12:54
  • Yes it will, as i said maybe you need to change the `bootstrap.php` and `autoload.php` access paths to make the app work. As an example in your `require __DIR__ . '/../../laravel-app/vendor/autoload.php';` use the `../..` as many times as you need to match your app logic. – Guille Apr 09 '22 at 12:58
  • @Guille Is there any solution so that `index.php` of root folder which is already there should not be affected? – user3653474 Apr 09 '22 at 13:07

1 Answers1

0

the most perfect way to do this is by moving all your laravel files outside public_html after that move all your files from public folder to public_html

then go to \App\Providers\AppServiceProvider and add the following lines to the register() method

$this->app->bind('path.public', function() {
    return base_path('public_html');
});

keep the other settings like .htaccess without change

I hope it's helpful

Ahmed Hassan
  • 579
  • 2
  • 6