简体   繁体   English

当用户未登录时,Laravel强制重定向到公用文件夹

[英]Laravel forces redirect to public folder when user is not logged in

I added this rule into the .htaccess to redirect all the requests to the public folder: 我将此规则添加到.htaccess以将所有请求重定向到公用文件夹:

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

This way I can strip the public word from the URI, although both mydomain.com/home and mydomain.com/public/home would work. 这样,尽管mydomain.com/homemydomain.com/public/home都可以工作,但我可以从URI中剥离public单词。

I now implemented the basic user authentication but what happens is that: 我现在实现了基本的用户身份验证,但是发生的是:

  1. if user requests for mydomain.com/admin and is not logged in, Laravel redirects him or her to mydomain.com/public/login instead of mydomain.com/login 如果用户请求mydomain.com/admin没有登录,Laravel重定向他或她mydomain.com/public/login代替mydomain.com/login
  2. when user authenticates himself or herself, Laravel redirects him or her to mydomain.com/public/admin instead of mydomain.com/admin 当用户对自己进行身份验证时,Laravel会将其重定向到mydomain.com/public/admin而不是mydomain.com/admin

Based on this, I guess that Laravel, somewhere, explicitates that redirects must be made at /public/whatever . 基于此,我猜想Laravel在某处明确指出必须在/public/whatever进行重定向。 I tried to figure out where redirect() helper is explicitated but I couldn't find it. 我试图找出在哪里redirect() helper被显式了,但是我找不到它。 My questions are: 我的问题是:

  • Is my assumption right? 我的假设正确吗?
  • If yes , where Laravel defines that the redirects must be made at /public/whatever ? 如果 ,Laravel在哪里定义必须在/public/whatever处进行重定向? Where I can find redirect() helper? 在哪里可以找到redirect()助手?
  • If no , why point 1 and 2 occur? 如果 ,为什么会出现第1点和第2点?

from the docs 文档

Apache 阿帕奇

The framework ships with a public/.htaccess file that is used to allow URLs without index.php. 该框架附带一个public / .htaccess文件,该文件用于允许没有index.php的URL。 If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module. 如果使用Apache服务Laravel应用程序,请确保启用mod_rewrite模块。

If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one: 如果Laravel随附的.htaccess文件不适用于您的Apache安装,请尝试以下操作:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

If your web host doesn't allow the FollowSymlinks option, try replacing it with Options +SymLinksIfOwnerMatch. 如果您的虚拟主机不允许使用FollowSymlinks选项,请尝试将其替换为Option + SymLinksIfOwnerMatch。

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

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