簡體   English   中英

使用基本身份驗證(htaccess)來限制對特定URL的訪問

[英]Using Basic Authentication (htaccess) to restrict access to a specific URL

我需要通過Apache使用基本身份驗證來限制對特定URL的訪問,例如我的網絡服務器上的http://mydomain.com/this/is/the/url 任何其他URL都應該是可以公開訪問的。 我已經看到您可以使用以下方法向文件添加特定規則:

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

我的問題是所有請求都使用mod-rewrite路由到控制器,所以我不認為我可以根據文件限制訪問。 任何想法都會最有幫助!

在.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/

我不確定這是否可行/幫助,但您可以在應用程序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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM