skip to Main Content

I have recently installed Laravel into my public_html folder. I want it so when I log into www.malhub.com it gets the contents of the public folder (public_html/public).

After trial and error, I was able to get it working somewhat. Now I have a 404 error, which is caused because the site (www.malhub.com) resolves to :

http://malhub.com/public/public_html

But my .htaccess code states:

RewriteRule ^(.*)$ public_html/public/$1 [L]

In other words, it looks for a public_html folder within the public folder (should just be the public folder)

I added some folders (test) just to make sense of how this works and am befuddled. It is going into the public folder and looking for another folder.

When I just try writing:

RewriteRule ^(.*)$ public/$1 [L]

or “public_html” or any combination of /../../ I keep getting 500 errors (that don’t show the url).

How does this line of code work, and what is the optimum way?

2

Answers


  1. By default the website will be load from public folder.
    If you want to remove public from your url,copy .htaccess file from public folder to root and replace the code with the following..

    <IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]
    
    RewriteCond %{REQUEST_URI} (.w+$) [NC]
    RewriteRule ^(.*)$ public/$1 
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php
    

    Login or Signup to reply.
  2. If you don’t want to remove all files and folder from the public folder, then just copy .htaccess to your root directory and rename server.php to index.php and last one step is if all resource files in /public directory couldn’t find and request URLs didn’t work for using asset() helper. Then, you need to add public to your helpers.php file.

    function asset($path, $secure = null)
    {
        return app('url')->asset($path, $secure);
    }
    

    To

    function asset($path, $secure = null)
    {
        return app('url')->asset("public/".$path, $secure);
    }
    

    You will fine the helpers.php in vendor/laravel/framework/src/Illuminate/Foundation/helpers.php.

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