{"id":10187,"date":"2020-03-06T01:01:00","date_gmt":"2020-03-05T19:31:00","guid":{"rendered":"https:\/\/wpproonline.com\/?p=356"},"modified":"2026-02-26T10:47:55","modified_gmt":"2026-02-26T10:47:55","slug":"how-to-deny-allow-access-to-files-using-htaccess-file","status":"publish","type":"post","link":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/","title":{"rendered":"How to deny\/allow access to files using .htaccess file"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Question:<\/h2>\n\n<p class=\"wp-block-paragraph\">How can I allow and deny HTTP access to files based on file extensions? I need to deny access to all TXT files.<\/p>\n\n<p><!--more--><\/p>\n\n<h2 class=\"wp-block-heading\">Answer:<\/h2>\n\n<p class=\"wp-block-paragraph\">Below you can find a simple example of how to control download access to files using a <em><strong><code>.htaccess<\/code><\/strong><\/em> file. In the first example, the following <strong><em><code>.htaccess<\/code><\/em><\/strong> code will block access to all files with a<strong><em> <code>.txt<\/code><\/em><\/strong> file extension for all requests resulting in <strong><em><code>HTTP ERROR 403: Forbidden.<\/code><\/em><\/strong><\/p>\n\n<pre data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;FilesMatch \".txt\"&gt;\n    Order Allow,Deny\n    Deny from All\n&lt;\/FilesMatch&gt;<\/pre>\n\n<p class=\"wp-block-paragraph\">If download access is required on the basis of the source IP address, it is possible to allow access on an IP basis. The following code will deny access to all of them and then allow access to the <em><strong><code>.txt<\/code><\/strong><\/em> file to requests coming from e.g. <strong><em>11.110.299.255<\/em><\/strong> IP address:<\/p>\n\n<pre data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;FilesMatch \".txt\"&gt;\n    Order Deny,Allow\n    Deny from All\n    Allow from 11.110.299.255\n&lt;\/FilesMatch&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Question: How can I allow and deny HTTP access to files based on file extensions? I need to deny access to all TXT files.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[82,85,86,72],"tags":[147,148,149,150],"class_list":["post-10187","post","type-post","status-publish","format-standard","hentry","category-aws","category-linux","category-ubuntu","category-wordpress","tag-allow","tag-allow-from-ip","tag-deny","tag-htacces"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to deny\/allow access to files using .htaccess file - DigitalHubZ<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to deny\/allow access to files using .htaccess file\" \/>\n<meta property=\"og:description\" content=\"Question: How can I allow and deny HTTP access to files based on file extensions? I need to deny access to all TXT files.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/\" \/>\n<meta property=\"og:site_name\" content=\"DigitalHubZ\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-05T19:31:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-26T10:47:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.digitalhubz.com\/blog\/wp-content\/uploads\/2023\/03\/digitalhubz.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1232\" \/>\n\t<meta property=\"og:image:height\" content=\"369\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DigitalHubZ\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DigitalHubZ\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/how-to-deny-allow-access-to-files-using-htaccess-file\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/how-to-deny-allow-access-to-files-using-htaccess-file\\\/\"},\"author\":{\"name\":\"DigitalHubZ\",\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/#\\\/schema\\\/person\\\/5a4074d837d6e5d22d665e5b7ca9e873\"},\"headline\":\"How to deny\\\/allow access to files using .htaccess file\",\"datePublished\":\"2020-03-05T19:31:00+00:00\",\"dateModified\":\"2026-02-26T10:47:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/how-to-deny-allow-access-to-files-using-htaccess-file\\\/\"},\"wordCount\":123,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/#organization\"},\"keywords\":[\"allow\",\"allow from IP\",\"deny\",\"htacces\"],\"articleSection\":[\"AWS\",\"Linux\",\"Ubuntu\",\"Wordpress\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/how-to-deny-allow-access-to-files-using-htaccess-file\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/how-to-deny-allow-access-to-files-using-htaccess-file\\\/\",\"url\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/how-to-deny-allow-access-to-files-using-htaccess-file\\\/\",\"name\":\"How to deny\\\/allow access to files using .htaccess file - DigitalHubZ\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/#website\"},\"datePublished\":\"2020-03-05T19:31:00+00:00\",\"dateModified\":\"2026-02-26T10:47:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/how-to-deny-allow-access-to-files-using-htaccess-file\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/how-to-deny-allow-access-to-files-using-htaccess-file\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/how-to-deny-allow-access-to-files-using-htaccess-file\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to deny\\\/allow access to files using .htaccess file\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/\",\"name\":\"DigitalHubZ\",\"description\":\"Future-Ready Digital Solutions\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/#organization\",\"name\":\"DigitalHubZ\",\"url\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/digitalhubz.webp\",\"contentUrl\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/digitalhubz.webp\",\"width\":1232,\"height\":369,\"caption\":\"DigitalHubZ\"},\"image\":{\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/#\\\/schema\\\/person\\\/5a4074d837d6e5d22d665e5b7ca9e873\",\"name\":\"DigitalHubZ\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/414c5bb85907e15e0f840541718ecc7420d52ea432b33f6a57761a674a52ebb7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/414c5bb85907e15e0f840541718ecc7420d52ea432b33f6a57761a674a52ebb7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/414c5bb85907e15e0f840541718ecc7420d52ea432b33f6a57761a674a52ebb7?s=96&d=mm&r=g\",\"caption\":\"DigitalHubZ\"},\"sameAs\":[\"https:\\\/\\\/digitalhubz.com\"],\"url\":\"https:\\\/\\\/www.digitalhubz.com\\\/blog\\\/author\\\/digi_v1_wp\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to deny\/allow access to files using .htaccess file - DigitalHubZ","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/","og_locale":"en_US","og_type":"article","og_title":"How to deny\/allow access to files using .htaccess file","og_description":"Question: How can I allow and deny HTTP access to files based on file extensions? I need to deny access to all TXT files.","og_url":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/","og_site_name":"DigitalHubZ","article_published_time":"2020-03-05T19:31:00+00:00","article_modified_time":"2026-02-26T10:47:55+00:00","og_image":[{"width":1232,"height":369,"url":"https:\/\/www.digitalhubz.com\/blog\/wp-content\/uploads\/2023\/03\/digitalhubz.webp","type":"image\/webp"}],"author":"DigitalHubZ","twitter_card":"summary_large_image","twitter_misc":{"Written by":"DigitalHubZ","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/#article","isPartOf":{"@id":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/"},"author":{"name":"DigitalHubZ","@id":"https:\/\/www.digitalhubz.com\/blog\/#\/schema\/person\/5a4074d837d6e5d22d665e5b7ca9e873"},"headline":"How to deny\/allow access to files using .htaccess file","datePublished":"2020-03-05T19:31:00+00:00","dateModified":"2026-02-26T10:47:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/"},"wordCount":123,"commentCount":6,"publisher":{"@id":"https:\/\/www.digitalhubz.com\/blog\/#organization"},"keywords":["allow","allow from IP","deny","htacces"],"articleSection":["AWS","Linux","Ubuntu","Wordpress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/","url":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/","name":"How to deny\/allow access to files using .htaccess file - DigitalHubZ","isPartOf":{"@id":"https:\/\/www.digitalhubz.com\/blog\/#website"},"datePublished":"2020-03-05T19:31:00+00:00","dateModified":"2026-02-26T10:47:55+00:00","breadcrumb":{"@id":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.digitalhubz.com\/blog\/how-to-deny-allow-access-to-files-using-htaccess-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.digitalhubz.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to deny\/allow access to files using .htaccess file"}]},{"@type":"WebSite","@id":"https:\/\/www.digitalhubz.com\/blog\/#website","url":"https:\/\/www.digitalhubz.com\/blog\/","name":"DigitalHubZ","description":"Future-Ready Digital Solutions","publisher":{"@id":"https:\/\/www.digitalhubz.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.digitalhubz.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.digitalhubz.com\/blog\/#organization","name":"DigitalHubZ","url":"https:\/\/www.digitalhubz.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.digitalhubz.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.digitalhubz.com\/blog\/wp-content\/uploads\/2023\/03\/digitalhubz.webp","contentUrl":"https:\/\/www.digitalhubz.com\/blog\/wp-content\/uploads\/2023\/03\/digitalhubz.webp","width":1232,"height":369,"caption":"DigitalHubZ"},"image":{"@id":"https:\/\/www.digitalhubz.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.digitalhubz.com\/blog\/#\/schema\/person\/5a4074d837d6e5d22d665e5b7ca9e873","name":"DigitalHubZ","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/414c5bb85907e15e0f840541718ecc7420d52ea432b33f6a57761a674a52ebb7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/414c5bb85907e15e0f840541718ecc7420d52ea432b33f6a57761a674a52ebb7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/414c5bb85907e15e0f840541718ecc7420d52ea432b33f6a57761a674a52ebb7?s=96&d=mm&r=g","caption":"DigitalHubZ"},"sameAs":["https:\/\/digitalhubz.com"],"url":"https:\/\/www.digitalhubz.com\/blog\/author\/digi_v1_wp\/"}]}},"_links":{"self":[{"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/posts\/10187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/comments?post=10187"}],"version-history":[{"count":4,"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/posts\/10187\/revisions"}],"predecessor-version":[{"id":54865,"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/posts\/10187\/revisions\/54865"}],"wp:attachment":[{"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/media?parent=10187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/categories?post=10187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.digitalhubz.com\/blog\/wp-json\/wp\/v2\/tags?post=10187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}