0

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

enter image description here

  • 1
    Wait, what? So when you visit `yourdomain.tld/.env` or `yourdomain.tld/composer.json`, you can see all the content? – Dragonsnap Oct 11 '20 at 14:54
  • Did you rename server.php to index.php at your laravel root directory? – STA Oct 11 '20 at 14:57
  • @Dragonsnap : nope,1st That is located at yourdomain.tld/home/.env and 2nd) that has been protected by bit ninja security (i mean its already permission protected but even though if someone tries to access it, that ip is blocked untill the solve captcha) – Talk is Cheap Show me Code Oct 11 '20 at 15:05
  • @sta : yes I tried doing that as well, so I moved .htaccess at public directory to yourdomain.tld/home directory and also renamed server.php to index.php – Talk is Cheap Show me Code Oct 11 '20 at 15:06
  • @sta: but it didnt worked – Talk is Cheap Show me Code Oct 11 '20 at 15:06
  • Consider this answer; https://stackoverflow.com/questions/28364496/laravel-5-remove-public-from-url – cednore Oct 11 '20 at 15:06
  • @ElektaKode : Hey , I have followed this question and I found it working, one issue though, all the urls That is generated in template is still including public in url, and to access them I have to keep another copy of .htaccess in my public folder as well. – Talk is Cheap Show me Code Oct 11 '20 at 15:58
  • @ElektaKode : if I change the APP_URL=https://yourdomain.tld/home/public in .env file to APP_URL=https://yourdomain.tld/home , it works fine but it breaks CSS and JS File ! – Talk is Cheap Show me Code Oct 11 '20 at 16:03
  • @TalkisCheapShowmeCode : Or you can just copy `.htaccess` file and `index.php` file from `public` folder to your project root and try your customization on them. – cednore Oct 11 '20 at 16:11
  • ok I have moved everything from public folder to project root and customized index.php and its working like charm, but one more doubt! if i removed old public folder, it gave me error that file dont found, so I think that too is needed, and one more question, which uploads folders is being used? – Talk is Cheap Show me Code Oct 11 '20 at 16:24
  • It is not recommended to remove the public folder because of that you get vulnerable and your database and other application settings that are in .env file in a simple text format gets exposed easily. I recommend you to login to your hosting, go to the path, then append /public. thats it 3 steps and youd be good to go. – Jawwad Ahmed Oct 11 '20 at 19:15
  • yes I did that, now ever URL that is printed by laraval is consiting of public in between, thats the exact issue – Talk is Cheap Show me Code Oct 12 '20 at 04:43

1 Answers1

1

I think there are 3 possible solutions:

  1. 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.

  1. 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.

  1. Your folder structure is incorrect. You might try to compare it with freshly installed Laravel.
Bulent
  • 3,307
  • 1
  • 14
  • 22