保护基于查询字符串参数与HTTP验证的URL [英] Protect a url with HTTP authentication based on query string parameter

查看:147
本文介绍了保护基于查询字符串参数与HTTP验证的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,像这样的链接:

I have a site with links like this:

http://www.example.com/index.php?id=1

http://www.example.com/index.php?id=3

等。

我想有htaccess的密码保护特定ID,说200。

I would like to have htaccess password protection for a specific ID, say 200.

我怎样才能做到这一点?

How can I do this?

推荐答案

这是不是直接的,但这里是一个方式,它可以在的.htaccess 做自己:

This is not straight forward but here is a way it can be done in .htaccess itself:

RewriteEngine On

# set URI to /index.php/200 if query string is id=200
RewriteCond %{QUERY_STRING} (?:^|&)id=(200|1)(?:&|$) [NC]
RewriteRule ^(index\.php)/?$ $1/%1 [NC]

# set SECURED var to 1 if URI is /index.php/200
SetEnvIfNoCase Request_URI "^/index\.php/(200|1)" SECURED

# enforce auth if SECURED=1
AuthType Basic
AuthName "Login Required"
AuthUserFile /full/path/to/passwords
Require valid-user
Order allow,deny
Allow from all
Deny from env=SECURED
Satisfy any

这篇关于保护基于查询字符串参数与HTTP验证的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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