问题
I have a Laravel 5.3
project on shared hosting located at the following address.
How to remove the public from URL?
Now the same question was asked at Remove public from URL Laravel 5.3 on shared hosting but many answers were asking to move all public content to root domain, but my root domain is already hosting something with index.php
in it.
Can you please tell me how to do it? All other information is same as the question shared, i.e default .htaccess
file in public as well as home (laravel installation) folder. Second I am in shared hosting, I cant change Vhost
or something.
Here is my folder structure inside https://yourdomain.tld/home folder
回答1:
I think there are 3 possible solutions:
- Since you use vhost instead of localhost, the problem might be the DocumentRoot declaration. I use Xampp, so the path and code will be based on that. In my case, the file that creates vhost is located:
C:\Xampp\apache\conf\extra\httpd-vhosts.conf
The vhost code is this:
<VirtualHost *:80>
DocumentRoot "C:/Xampp/htdocs/mydomain/home/public"
ServerName mydomain.tld/home
ErrorLog "logs/mydomain-e1rror.log"
CustomLog "logs/mydomain-access.log" common
</VirtualHost>
BTW, make sure you 127.0.0.1 mydomain.tld in "etc" file if you use a Windows machine.
When you enter www.mydomain.tld it should hit the index.php file that is located in public folder.
- Since you use very old version of Laravel, I suppose you download it from liveserver. When we deploy our app, we make some changes in public/index.php file to tell our app where Laravel is. Look for
require __DIR__.'/../vendor/autoload.php'; //
I think this is different in your index.php file. BTW, I don't know if this path is different in version 5.3.
- Your folder structure is incorrect. You might try to compare it with freshly installed Laravel.
来源:https://stackoverflow.com/questions/64305191/how-to-remove-public-from-laravel-url-hosted-on-child-folder