search

Home  >  Q&A  >  body text

apache - .htaccess How to set IP whitelist permissions for a specific request?

For example, http://demo.com/hello, I want to restrict access to only the IP address 211.125.10.5. Access from other IP addresses will return 403. How should I write .htaccess

PS1:
/hello is not a directory, so you cannot use .htaccess directory-based IP restrictions

PS2:
The website is based on WordPress and now has the following rewrite rules.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

PS3:
I just tried a solution, but it was always 500
This solution was rejected, the Location directive cannot be written in the .htaccess file...

<Location /hello/ >
	Order Deny,Allow
	Deny from all
	Allow from 211.125.10.5
</Location>
PHP中文网PHP中文网2825 days ago1087

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-16 17:06:32

    Apache will search whether there is .htaccess in each directory, so you only need to set it in the subdirectory. The restriction method is the same as the main directory restriction.
    Or don't use Location,使用Directory块来限制,或者使用files to limit the executable file.

    reply
    0
  • Cancelreply