How to block access to a particular route in .htaccess file

纵饮孤独 提交于 2019-12-25 17:46:14

问题


I need to block access to a particular route in my web application using a .htaccess file for everyone except a list of IP's. When I say block and whitelist IP's I want to use the following on particular route

order deny,allow
deny from all
allow from 1.1.1.1
allow from 2.2.2.2

I tried using the Location directive, but it is not allowed in .htaccess.

I do not have access to the server config file since it is a managed hosting provider

The route I want to block is for eg: http://www.example.com/route1

Is there a way?

Thanks for the help in advance


回答1:


You can definitely achieve this using multiple methods.

.htaccess files:

<files route1>
    order deny,allow
    deny from all
    allow from my.ip.address
</files>



回答2:


If you are looking at whitelisting multiple ip's I would suggest the follow method:

<Files myfile.php>
  order deny,allow
  deny from all
  allow from env=allowip

  #Office 1
  #132.11.32.222
  SetEnvIf X-FORWARDED-FOR "^132\.11\.32\.222" allowip

  #Office 2
  #142.11.32.222
  SetEnvIf X-FORWARDED-FOR "^142\.11\.32\.222" allowip
</Files>


来源:https://stackoverflow.com/questions/32334514/how-to-block-access-to-a-particular-route-in-htaccess-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!