URL rewriting and htpasswd


URL rewriting and htpasswd

我正在我的网站上使用URL重写,我想通过.htpasswd文件将身份验证添加到我的一个目录中。

我的网站是这样构建的

/home/website/
/home/website/protected/
/home/website/protected/.htaccess
/home/website/protected/.htpasswd
/home/website/protected/admin.php
/home/website/.htaccess
/home/website/index.php
/home/website/index_protected.php

在/home/website/目录上,我得到了一个 .htaccess 文件:

RewriteRule ^directory([0-9]+)/protected/([a-z0-9-_]+).php   /home/website/protected/admin.php?d=$1&p=$2 [QSA]

使用类似网址

http//website/directory1/protected/test.php 

你会打电话

/home/website/1/protected/admin.php?d=1&p=test

在/protected/目录的 .htaccess 上,我得到了:

AuthName "Page d'administration protégée"
AuthType Basic
AuthUserFile "/home/website/protected/.htpasswd"
Require valid-user

在/protected/目录中的 .htpasswd 上,我得到了:

admin:crypted_password

但我的问题是,当我打电话时

http//website/directory1/protected/test.php

我从来没有收到身份验证窗口,有什么想法可以解决这个问题吗?

您可以尝试将带有基本身份验证指令的 .htaccess 文件放置到受保护的目录中。

这主要发生在服务器不使用.htaccess文件时。检查是否允许在/home/website/protected/而不仅仅是/home/website/中使用该文件。