Avoid public folder of laravel and open directly the root in web server

前端 未结 9 2073
礼貌的吻别
礼貌的吻别 2020-11-29 16:45

I was going through all possible sample on internet to solve this. Still it is an headache.

I just want to avoid the \'public\' in www.mylaravelsite.com/public

相关标签:
9条回答
  • 2020-11-29 17:22

    Create .htaccess in root folder and write these line

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
    

    For production server it is recommended that you point your domain directly to the public folder

    0 讨论(0)
  • 2020-11-29 17:24

    create .htacess file in the root directory of your laravel project and put this code in.

    <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
    

    0 讨论(0)
  • 2020-11-29 17:31

    It sounds like the information you are missing is:

    Documentroot

    This is also called the "web root". Apache specifically calls it the DocumentRoot - Click that link for the official explanation.

    Basically what it does is set which directory the server pulls files from. In Laravel, the document root should be the public folder.

    Setting the DocumentRoot to public means that going to http://mylaravelsite.com in the browser will infact be "pointing" to the public folder as you want.

    In the .htaccess file (actually, more likely in the virtual host configuration), you can set the DocumentRoot for your site:

    DocumentRoot /path/to/laravel-app/public
    

    How you set this up depends on your hosting. Each hosting has different ways to setup a website and so we cannot answer that specifically for you - you should consult your web hostings tech support. The key point is that the public directory should be the web root, while everything else should be "behind the web root".

    Fair warning tho: some hosting providers do not give you enough access to accomplish that.

    0 讨论(0)
  • 2020-11-29 17:33

    Just add .htaccess file on Laravel root if it's not present and add following lines in it, that's it,

    <IfModule mod_rewrite.c>  
       RewriteEngine On 
       RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
    
    0 讨论(0)
  • 2020-11-29 17:37

    point your web directory to public/. If you are using apache this will work:

    <VirtualHost *:80>
      DocumentRoot /var/www.mylaravelsite.com/public/
      ServerName www.mylaravelsite.com
    </VirtualHost>
    
    0 讨论(0)
  • 2020-11-29 17:37

    All you just need to change .env file in your laravel project files. if your laravel project inside in

    Root/domain/public_html/laravel/

    Go to .env file and edit

    you need to edit app url path which should be

    APP_URL=http://www.domainname.com/laravel/public/

    Thats it your project will run now. if your laravel files is in public_html, then your app url must be like this

    APP_URL=http://www.domainname.com

    Thanks

    0 讨论(0)
提交回复
热议问题