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

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

问题描述

该网站上共享主机。我需要密码保护单个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和满足任何指令的组合来做到这一点。您可以使用 SetEnvIf之后要检查的 REQUEST_URI ,即使它不是一个物理路径。然后,您可以检查变量是在设置允许语句。因此,无论你需要用密码登录,或允许可以让你在没有密码:

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

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

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