duankanjian4642 2015-10-22 13:31
浏览 25
已采纳

安全Laravel网站托管

I developed a website using laravel and on my web hoster I have not find the public directory so , I changed the server.php
From

require_once __DIR__.'/public/index.php';

To

require_once __DIR__.'/index.php';

and I moved all the contents of the public folder in the root and the website works very well BUT the problem is when I put for example http://mywebsite.com/.env I can show the content of .env so my site is not protected.

The Question :

How can I protect my files and directories ?

Example of structure I want:

index.php
.htaccess
favicon.ico
img/
css/
js/
laravel/
      app/
      bootstrap/
      database/
      config/
      storage/
     .env
     server.php
     ...

Content of the root of my site => the public folder content

laravel directory => the other directories and files

  • 写回答

2条回答 默认 最新

  • douchilian1009 2015-10-22 15:56
    关注

    Place everything back in the public folder and revert the changes to server.php. Then in your top level directory add a .htaccess file with the code below:

    <IfModule mod_rewrite.c>
       RewriteEngine On 
       RewriteRule ^(.*)$ public/$1 [L]
    </IfModule>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?