Block IP from accessing a certain page on website


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

Is there a way to block an IP from accessing a page (e.g., 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, but the effective URL is 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} ^$ RewriteRule^ mypage$ - [F]

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



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:



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