Block IP from accessing a certain page on website

Hi,

I have the following code in my .htaccess file to block an IP from accessing a file on my site and it works fine.

<Files mypage.html>
	Order Deny,Allow
	Deny from XXX.XXX.XXX.XXX
</Files>

Is there a way to block an IP from accessing a page (e.g., mydomain.com/mypage/) which is neither a file nor a directory? Thanks for a any ideas.

I’m curious to know, what else is there?

It’s just a permalink, not a file or directory. Like a rewrite from mydomain.com/page.php?page=mypage, but the effective URL is mydomain.com/mypage/. Like a blog post, it is not a file or directory but it is a page of the site.

I agree with Alan: That’s a strange thing to ask for (not a file and not a directory - what else does Apache deal with?).

Anyway, mod_rewrite can block specific requests from a specific remote IP address:

RewriteEngine on RewriteCond %{REMOTE_ADDR} ^xxx.xxx.xxx.xxx$ RewriteRule^ mypage$ - [F]

If you need to learn more about mod_rewrite, try my tutorial at http://dk.co.nz/seo. It’s helped may SiteMembers over the past years and should help you with simple questions like this.

Regards,

DK

1 Like

Thanks DK, that’s what I needed.

Whoops! Of all things, I forgot the backslashes in the RewriteCond’s regex:

Sorry about that! :blush:

Regards,

DK

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.