2011-03-23 152 views
7

我需要限制对特定URL的访问,例如, http://mydomain.com/this/is/the/url在我的网络服务器上使用基本身份验证通过Apache。任何其他URL都应公开访问。我已经看到了你可以使用添加特定规则文件:使用基本身份验证(htaccess)限制对特定URL的访问

<Files "mypage.html"> 
    Require valid-user 
</Files> 

我的问题是,所有的请求路由到使用国防部重写控制器,所以我不认为我可以基于文件限制访问。任何想法将是最有帮助的!

回答

0

我不确定这是否可行/帮助,但可以在应用程序web.xml中指定某些内容。

<security-constraint> 
    <display-name>Public access</display-name> 
    <web-resource-collection> 
     <web-resource-name>PublicPages</web-resource-name> 
     <description>Public</description> 
     <url-pattern>/servlet/*</url-pattern> 
    </web-resource-collection> 
    <user-data-constraint> 
     <transport-guarantee>NONE</transport-guarantee> 
    </user-data-constraint> 
    </security-constraint> 
    <security-constraint> 
    <display-name>Secured access</display-name> 
    <web-resource-collection> 
     <web-resource-name>SecuredPages</web-resource-name> 
     <description>Secured pages</description> 
     <url-pattern>/services/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <description>General Access</description> 
     <role-name>*</role-name> 
    </auth-constraint> 
    <user-data-constraint> 
     <description>SSL not required</description> 
     <transport-guarantee>NONE</transport-guarantee> 
    </user-data-constraint> 
    </security-constraint> 
    <login-config> 
    <auth-method>BASIC</auth-method> 
    <realm-name>SecurePages</realm-name> 
    </login-config> 
    <security-role> 
    <description>General Access</description> 
    <role-name>*</role-name> 
    </security-role> 
1

在.htacess文件,你应该把:

AuthType Basic 
AuthName "Need to login" 
AuthUserFile .htpasswd file location ; 
Require user USER 

//AuthName is login prompt message 
//AuthUserFile is physical .htpasswd file location i.e. 
C:/xampp/htdocs/basic/.htpasswd 
//Require user is for a specific user i.e. the username you want to 
authenticate 

要生成htpasswd文件,你可以使用: - http://www.htaccesstools.com/htpasswd-generator/

相关问题