laravel htaccess允许目录

时间:2017-11-06 22:45:14

标签: laravel .htaccess cpanel

我在example.com/staging有一个受密码保护的目录。

如果我输入example.com/js,我会收到一个文件夹列表。

但是,如果我输入example.com/staging,我会在example.com(而非example.com/staging)处获得由Laravel网站生成的404错误页面,而不是密码框。这是为什么?

以下是我在example.com的public_html文件夹(主目录)中的.htaccess文件:

AddType application/x-httpd-php70 .php
<IfModule mod_rewrite.c>
  <IfModule mod_negotiation.c>
      Options -MultiViews
  </IfModule>

  RewriteEngine On

  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # Redirect Trailing Slashes If Not A Folder...
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)/$ /$1 [L,R=301]

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

  # Handle Authorization Header
  RewriteCond %{HTTP:Authorization} .
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

</IfModule>

我的.htaccess文件位于example.com/staging

AuthType Basic
AuthName "Staging"
AuthUserFile "/home/example/.htpasswds/public_html/staging/passwd"
require valid-user

2 个答案:

答案 0 :(得分:0)

AuthUserFile的目录路径中删除引号,这些引号不应该存在。

你的目录路径看起来也很奇怪,你的.htpasswd文件不应该位于路径的中间,而应该在最后。例如:

AuthUserFile /this/is/your/dir/.htpasswd

我确定是,但作为补充,您正在加密密码? Apache不接受未正确加密的密码。如果需要,您可以使用本网站提供帮助:http://www.htaccesstools.com/htpasswd-generator/

答案 1 :(得分:0)

我找到了答案 here

将以下行添加到受保护目录中的htaccess文件:

ErrorDocument 401 "Authorisation Required"