【问题标题】:Htpasswd specific url in laravel htaccesslaravel htaccess 中的 Htpasswd 特定 url
【发布时间】:2020-02-10 21:24:30
【问题描述】:

我有一个 Laravel 应用程序,我想在其中限制对特定 URL(特别是 api 文档的 url)/api/documentation 的访问。我看过这个post 并尝试过,但我不断收到内部服务器错误,我不知道如何放置代码。

这是我的.htaccess 就在这里。到目前为止默认的 laravel .htaccesss:

<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>

我必须在哪里或如何将代码放在这个 post 上?

谢谢。

【问题讨论】:

    标签: laravel apache .htaccess


    【解决方案1】:

    我可能会使用不同形式的身份验证。但是,如果您打算使用 HTTP 身份验证,至少要确保在生成 htpasswd 文件时使用 bcrypt 或其他安全的东西。

    但是要回答你的问题...

    你的.htaccess 文件应该有这样的内容:

    AuthType Basic
    AuthName "Super Secret"
    AuthUserFile /some/location/where/your/.htpasswd/file/is
    Require valid-user
    

    【讨论】:

    • 但这会锁定我网站中的每个网址,对吧?我只想限制一个特定的 URL,即 /api/documentation
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    相关资源
    最近更新 更多