密码保护特定 URL [英] Password protect a specific URL

查看:32
本文介绍了密码保护特定 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该站点位于共享主机上.我需要密码保护单个 URL.

The site is on shared hosting. I need to password protect a single URL.

http://www.example.com/pretty/url

显然,这不是我要保护的物理文件路径,只是那个特定的 URL.

Obviously that's not a physical file path I'm trying to protect, it's just that particular URL.

任何使用 .htaccess 的快速解决方案?

Any quick solution with .htaccess?

推荐答案

您应该能够使用 mod_env 和 Satisfy any 指令的组合来做到这一点.您可以使用 SetEnvIf 来检查 Request_URI,即使它不是物理路径.然后,您可以检查变量是否在 Allow 语句中设置.因此,要么您需要使用密码登录,要么 Allow 让您无需密码即可登录:

You should be able to do this using the combination of mod_env and the Satisfy any directive. You can use SetEnvIf to check against the Request_URI, even if it's not a physical path. You can then check if the variable is set in an Allow statement. So either you need to log in with password, or the Allow lets you in without password:

# Do the regex check against the URI here, if match, set the "require_auth" var
SetEnvIf Request_URI ^/pretty/url require_auth=true

# Auth stuff
AuthUserFile /var/www/htpasswd
AuthName "Password Protected"
AuthType Basic

# Setup a deny/allow
Order Deny,Allow
# Deny from everyone
Deny from all
# except if either of these are satisfied
Satisfy any
# 1. a valid authenticated user
Require valid-user
# or 2. the "require_auth" var is NOT set
Allow from env=!require_auth

这篇关于密码保护特定 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆