简体   繁体   English

如何从根文件夹重定向到Laravel中的公用文件夹

[英]How to redirect from root folder to public folder in laravel

I have a root folder: 我有一个根文件夹:

/www/

but I need to make the user to enter to this folder: 但我需要让用户输入此文件夹:

/www/public/

how can I do it using .htaccess 我如何使用.htaccess

Because you are on a shared hosting I'll give you this idea, but this shouldn't be the case on a proper development environment. 因为您位于共享主机上,所以我将为您提供这个想法,但是在适当的开发环境中,情况并非如此。

RewriteEngine On

RewriteCond %{THE_REQUEST} public/
RewriteRule ^public/(.*) http://mydomain.com/$1 [R=301,L]

RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(.*)$ /public/$1 [L]

或者,您可以将/public文件夹中的所有内容移至根目录,然后只需修改index.php的路径

I had the same problem with one of our servers. 我的一台服务器也遇到了同样的问题。 You don't actually have to use the public folder, it's just an extra security precaution. 实际上,您不必使用公用文件夹,这只是一个额外的安全预防措施。

Open the bootstrap folder. 打开引导文件夹。 In there you will find a file called "paths.php". 在这里,您将找到一个名为“ paths.php”的文件。 Open it and it will contain an array. 打开它,它将包含一个数组。 Change the public value to __DIR__.'/..' . 将公共值更改为__DIR__.'/..'

Then you can just use the folder with all of your laravel directories as your public folder. 然后,您可以仅使用所有laravel目录作为公用文件夹的文件夹。

You would of course have to move the default files (.htaccess, index.php and robots.txt) from the public folder, to your laravel folder. 当然,您必须将默认文件(.htaccess,index.php和robots.txt)从公用文件夹移动到laravel文件夹。

If you want to redirect to public then copy and past to .htaccess file of following code :- 如果要重定向到公共,则复制并粘贴以下代码的.htaccess文件:-

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public [L]

This .htaccess file store on root folder of your project. 该.htaccess文件存储在项目的根文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM