欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Restrict URL's starting with /abc to specific IP's [.htaccess guru]

Restrict URL's starting with /abc to specific IP's [.htaccess guru]

Permalink
I'm trying to protect URL's, starting with a specific slug (let's say /abc), by allowing specific IP's only. Let us assume my IP address is 123.123.123.123. I have the following htaccess code, which does the exact opposite (only allowing /abc and blocking the rest):

RewriteCond %{REQUEST_URI} !^/abc
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteRule ^(.*)$ - [R=403,L]  # 好像 要把 前后的^和$去掉


Now, does anyone know how to turn that around? So allow everything, EXCEPT the URL's starting with /abc? I tried removing the exclamation mark and several other things, with no success. The code above works though, but that's not what I want to achieve unfortunately.

ramonleenders
View Replies: 
jero replied on  at  Permalink Reply
jero
Try this:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/abc
RewriteCond %{REMOTE_ADDR} !=10.0.0.1
RewriteCond %{REMOTE_ADDR} !=10.0.0.2
RewriteCond %{REMOTE_ADDR} !=10.0.0.3
RewriteRule . http://www.bbc.co.uk [R=301,L]


if the url begins with /abc and the remote address is not one of the three listed, send the browser on its merry way.

来自  https://www.concrete5.org/community/forums/chat/restrict-urls-starting-with-abc-to-specific-ips-.hta...

普通分类: