简体   繁体   English

.htaccess拒绝除Laravel上的一个文件以外的所有内容

[英].htaccess deny everything except one file on Laravel

I am using the Laravel platform for my website. 我正在为我的网站使用Laravel平台。 What I want to achieve is to show only one web page with some info about the website. 我要实现的是仅显示一个包含有关该网站的信息的网页。 All other pages are still in development mode, so i want them to protect with .htaccess. 所有其他页面仍处于开发模式,因此我希望它们使用.htaccess保护。

Here is my .htaccess file, unfortunately it is asking for password for every single page: 这是我的.htaccess文件,不幸的是,它要求每个页面输入密码:

AuthName "myweb"
AuthUserFile "/home/passwd"
AuthType Basic
require valid-user

<Files "*">
Require valid-user
</Files>

<Files "start.html">
Allow from all 
Satisfy Any
</Files>

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

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

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

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

If there is some solution with .htaccess it will be great, but if Laravel offers an easy solution (except the maintenance mode) I can except that too. 如果.htaccess有一些解决方案,那会很棒,但是如果Laravel提供一个简单的解决方案(维护模式除外),我也可以做到。

Thanks in advice ! 多谢指教!

Try this in the top of your routes.php (or web.php depending on version) 在您的routes.php(或根据版本的web.php)顶部尝试此操作

if (getenv('REMOTE_ADDR') != '192.168.6.3' && !\Request::is('/')) {
    abort(404);
}

It says if the Request is not the home screen and the IP address is not my IP address, abort with a 404. 它说如果“请求”不是主屏幕并且IP地址不是我的IP地址,请使用404中止。

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

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