{"id":30089,"date":"2024-11-12T12:39:30","date_gmt":"2024-11-12T12:39:30","guid":{"rendered":"https:\/\/www.seobility.net\/en\/blog\/wiki\/htaccess\/"},"modified":"2025-02-26T09:23:44","modified_gmt":"2025-02-26T09:23:44","slug":"htaccess","status":"publish","type":"wiki","link":"https:\/\/www.seobility.net\/en\/wiki\/htaccess","title":{"rendered":".htaccess"},"content":{"rendered":"<h2><span class=\"mw-headline\" id=\"Definition\">Definition<\/span><\/h2>\n<div class=\"thumb tright\">\n<div class=\"thumbinner\" style=\"width:452px;\"><a href=\"https:\/\/www.seobility.net\/en\/wiki\/images\/4\/4a\/Htaccess.png\"><img decoding=\"async\" alt=\"htaccess\" src=\"\/en\/wiki\/images\/thumb\/4\/4a\/Htaccess.png\/450px-Htaccess.png\" width=\"450\" height=\"340\" class=\"thumbimage\" srcset=\"\/en\/wiki\/images\/thumb\/4\/4a\/Htaccess.png\/675px-Htaccess.png 1.5x, \/en\/wiki\/images\/4\/4a\/Htaccess.png 2x\" \/><\/a>  <\/p>\n<div class=\"thumbcaption\"><b>Figure:<\/b> .htaccess &#8211; Author: Seobility &#8211; License: <a href=\"\/en\/wiki\/creative-commons-license-by-sa-4-0\" title=\"Creative Commons License BY-SA 4.0\">CC BY-SA 4.0<\/a><\/div>\n<\/div>\n<\/div>\n<p>\u201c.htaccess\u201d is a powerful file whose function is to give instructions to the server. The name stands for \u201c<a href=\"\/en\/wiki\/Hypertext\" title=\"Hypertext\">Hypertext<\/a> Access\u201d, which refers to its original function of controlling user access to several text-based website files. When this tool was first devised, its main role was to limit access to specific parts of a site. By coding certain instructions into an .htaccess file, a system administrator was able to set up password-only access to a page or directory. Nowadays, the functionality of .htaccess has been expanded to several other uses, as will be discussed further down in this article.\n<\/p>\n<h3><span class=\"mw-headline\" id=\"How_is_.htaccess_different_to_httpd.conf.3F\">How is .htaccess different to httpd.conf?<\/span><\/h3>\n<p>These two files are used to change server configuration or to give the server additional instructions.\n<\/p>\n<p>However, httpd.conf is the main or master configuration file, and there can only be one instance of it. On the other hand, .htaccess can exist more than once and in multiple specific directories. Moreover, any directives included in httpd.conf are read once when the server, whereas those placed in .htaccess will be read every time a page is loaded, either in the directory where it lives or in any of its subdirectories.\n<\/p>\n<h2><span class=\"mw-headline\" id=\"How_to_create_an_.htaccess_file\">How to create an .htaccess file<\/span><\/h2>\n<p>To create a new .htaccess file, open a new document using a plain text editor, such as Notepad++, Brackets, or TextMate. As mentioned before, .htaccess essentially gives the server instructions, so the specific content will vary depending on what you want to achieve for each given site. Some examples are listed in section 3 of this article.\n<\/p>\n<p>Once the instructions have been coded, save the changes. To do this:\n<\/p>\n<ul>\n<li> Navigate to File &gt; Save As in your text editor. This will open a new dialogue box.<\/li>\n<li> Type the file name as .htaccess<\/li>\n<li> Under file name, the dialogue box will also have a \u201cfile type\u201d or \u201csave as type\u201d option. Set this to \u201cAll Files\u201d.<\/li>\n<li> Ensure the file is saved without any extension. Some editors will have .txt as a default extension \u2013 if so, delete it from the name.<\/li>\n<li> Ensure it&#8217;s not saved in UTF-8, but instead in <a href=\"\/en\/wiki\/ASCII\" title=\"ASCII\">ASCII<\/a> format.<\/li>\n<\/ul>\n<p>.htaccess can then be uploaded to the <a href=\"\/en\/wiki\/Root_Directory\" title=\"Root Directory\">root directory<\/a>, either by using a web-based file management system such as cPanel or via <a href=\"\/en\/wiki\/ftp-file-transfer-protocol\" title=\"FTP (File Transfer Protocol)\">FTP<\/a>. However, it can also be uploaded to other parts of a website. There might be multiple .htaccess files in directories and subdirectories other than root or public_html. In any case and before uploading it, it\u2019s important to remember that .htaccess has the ability to override other instructions that may be in child (or lower) directories.\n<\/p>\n<h2><span class=\"mw-headline\" id=\"What_is_.htaccess_used_for.3F\">What is .htaccess used for?<\/span><\/h2>\n<p>.htaccess can serve a variety of functions, depending on the specific directives it contains. Some of the most common uses include:\n<\/p>\n<h3><span class=\"mw-headline\" id=\"Rewriting_dynamic_URLs_into_static_URLs\">Rewriting dynamic URLs into static URLs<\/span><\/h3>\n<p>PHP-generated static URLs are preferable from an SEO and search ranking perspective. The following code can be inserted into the .htaccecss file to rename a dynamic URL into a static URL.\n<\/p>\n<pre>RewriteEngine On\r\nRewriteRule (.*)_(.*).html$ \/example.php?url_isbn=$1 [qsappend,L]<\/pre>\n<p>In the example above, \/example.php is the dynamic URL that is to be rewritten to \/example-1.html, with 1 being a backreference.\n<\/p>\n<h3><span class=\"mw-headline\" id=\"Setting_up_password-protection\">Setting up password-protection<\/span><\/h3>\n<p>Some sites must restrict users from accessing certain pages or directories. This requires setting up two files:\n<\/p>\n<p>An .htpasswd file that stores usernames and passwords saved outside the public directory so it cannot be publicly accessed:\n<\/p>\n<pre>user1:password1\r\nuser2:password2\r\nuser3:password3<\/pre>\n<p>An .htaccess file with the following instructions:\n<\/p>\n<pre>AuthType Basic\r\nAuthName \"restricted area\"\r\nAuthUserFile \/&lt;absolute path to password file&gt;\/.htpasswd\r\nAuthPGAuthoritative Off\r\nrequire user User1 User2 User3<\/pre>\n<h3><span class=\"mw-headline\" id=\"Redirects\">Redirects<\/span><\/h3>\n<p>To automatically redirect site visitors from an old to a new page location while maintaining SEO ranking, the following code can be added:\n<\/p>\n<pre>Redirect 301 \/old-path\/file.html https:\/\/www.example.com\/new-path\/file.html<\/pre>\n<p>To redirect visitors from an old domain to a new domain:\n<\/p>\n<pre>RewriteCond&#160;%{REQUEST_URI} (.*)\r\nRewriteRule ^(.*)$ https:\/\/new-domain.tld\/$1 [L,R=301]]<\/pre>\n<h3><span class=\"mw-headline\" id=\"Blocking_specific_IP-addresses\">Blocking specific IP-addresses<\/span><\/h3>\n<p>In some cases, it may be necessary to blacklist certain <a href=\"\/en\/wiki\/IP_Address\" title=\"IP Address\">IP addresses<\/a> from accessing a website. Blocking IP addresses can be achieved by adding the following instructions:\n<\/p>\n<pre>order allow,deny\r\ndeny from 111.1.1.1\r\nallow from all<\/pre>\n<p>In the example above, 111.1.1.1 is the IP address to be blocked. Additional IPs can be blocked by adding them above \u201callow from all\u201d. For example:\n<\/p>\n<pre>order allow,deny\r\ndeny from 111.1.1.1\r\ndeny from 222.2.2.2\r\nallow from all<\/pre>\n<h2><span class=\"mw-headline\" id=\"When_should_an_.htaccess_file_be_used.3F\">When should an .htaccess file be used?<\/span><\/h2>\n<p>Because this is an incredibly powerful part of a website, incorrect use of an .htaccess file can cause significant damage. Therefore, it\u2019s essential that it is only edited or created by those who are knowledgeable about server configuration. This is one of the reasons why .htaccess files are typically hidden and also why a warning message is usually displayed every time an attempt to edit them is made.\n<\/p>\n<h2><span class=\"mw-headline\" id=\"Related_links\">Related links<\/span><\/h2>\n<ul>\n<li> <a rel=\"nofollow\" class=\"external free\" href=\"https:\/\/www.whoishostingthis.com\/resources\/htaccess\/\">https:\/\/www.whoishostingthis.com\/resources\/htaccess\/<\/a><\/li>\n<li> <a rel=\"nofollow\" class=\"external free\" href=\"https:\/\/phoenixnap.com\/kb\/how-to-set-up-enable-htacc\">https:\/\/phoenixnap.com\/kb\/how-to-set-up-enable-htacc<\/a><\/li>\n<\/ul>\n<h2><span class=\"mw-headline\" id=\"Similar_articles\">Similar articles<\/span><\/h2>\n<ul>\n<li> <a href=\"\/en\/wiki\/SEO-friendly_URLs\" title=\"SEO-friendly URLs\">SEO-friendly URLs<\/a><\/li>\n<li> <a href=\"\/en\/wiki\/WWW_Redirect\" title=\"WWW Redirect\">WWW Redirect<\/a><\/li>\n<\/ul>\n<p><script type=\"application\/ld+json\">\n   {\n     \"@context\": \"https:\/\/schema.org\/\",\n     \"@type\": \"ImageObject\",\n     \"contentUrl\": \"https:\/\/www.seobility.net\/en\/wiki\/images\/4\/4a\/Htaccess.png\",\n     \"license\": \"https:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\",\n     \"acquireLicensePage\": \"https:\/\/www.seobility.net\/en\/wiki\/creative-commons-license-by-sa-4-0\"\n   }\n   <\/script>\n<\/p>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"Article\",\n  \"author\": {\n    \"@type\": \"Organization\",\n    \"name\": \"Seobility\",\n    \"url\": \"https:\/\/www.seobility.net\/\"\n  }\n}\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Definition Figure: .htaccess &#8211; Author: Seobility &#8211; License: CC BY-SA 4.0 \u201c.htaccess\u201d is a powerful file whose function is to give instructions to the server. The name stands for \u201cHypertext Access\u201d, which refers to its original function of controlling user access to several text-based website files. When this tool was first devised, its main role [&hellip;]<\/p>\n","protected":false},"author":38,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"class_list":["post-30089","wiki","type-wiki","status-publish","hentry","wiki_categories-web-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is .htaccess and what is it used for? - Seobility Wiki<\/title>\n<meta name=\"description\" content=\".htaccess (hypertext access) is a powerful file whose function is to give instructions to the server. Learn more ...\" \/>\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.seobility.net\/en\/wiki\/htaccess\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is .htaccess and what is it used for? - Seobility Wiki\" \/>\n<meta property=\"og:description\" content=\".htaccess (hypertext access) is a powerful file whose function is to give instructions to the server. Learn more ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.seobility.net\/en\/wiki\/htaccess\" \/>\n<meta property=\"og:site_name\" content=\"Seobility\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/seobility.net\/\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-26T09:23:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.seobility.net\/wp-content\/uploads\/2025\/06\/seobility-og-image.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@seobility_net\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"ScholarlyArticle\",\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\\\/htaccess#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\\\/htaccess\"},\"author\":{\"name\":\"Seobility Wiki Team\",\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/#\\\/schema\\\/person\\\/c838e66a3b46262b4c963df5cd5b2d8a\"},\"headline\":\".htaccess\",\"datePublished\":\"2024-11-12T12:39:30+00:00\",\"dateModified\":\"2025-02-26T09:23:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\\\/htaccess\"},\"wordCount\":757,\"commentCount\":0,\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\\\/htaccess#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\\\/htaccess\",\"url\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\\\/htaccess\",\"name\":\"What is .htaccess and what is it used for? - Seobility Wiki\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/#website\"},\"datePublished\":\"2024-11-12T12:39:30+00:00\",\"dateModified\":\"2025-02-26T09:23:44+00:00\",\"description\":\".htaccess (hypertext access) is a powerful file whose function is to give instructions to the server. Learn more ...\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\\\/htaccess#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\\\/htaccess\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\\\/htaccess#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Wiki\",\"item\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/wiki\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\".htaccess\",\"item\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/wp-json\\\/wp\\\/v2\\\/wiki\\\/30089\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/\",\"name\":\"Seobility\",\"description\":\"Online SEO Software &amp; Tools For Better Rankings\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/#\\\/schema\\\/person\\\/c838e66a3b46262b4c963df5cd5b2d8a\",\"name\":\"Seobility Wiki Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.seobility.net\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/Seobility-S-2025-150x150.png\",\"url\":\"https:\\\/\\\/www.seobility.net\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/Seobility-S-2025-150x150.png\",\"contentUrl\":\"https:\\\/\\\/www.seobility.net\\\/wp-content\\\/uploads\\\/2025\\\/06\\\/Seobility-S-2025-150x150.png\",\"caption\":\"Seobility Wiki Team\"},\"description\":\"The Seobility Wiki team consists of seasoned SEOs, digital marketing professionals, and business experts with combined hands-on experience in SEO, online marketing and web development. All our articles went through a multi-level editorial process to provide you with the best possible quality and truly helpful information. Learn more about the people behind the Seobility Wiki.\",\"url\":\"https:\\\/\\\/www.seobility.net\\\/en\\\/blog\\\/author\\\/seobility-wiki-team\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is .htaccess and what is it used for? - Seobility Wiki","description":".htaccess (hypertext access) is a powerful file whose function is to give instructions to the server. Learn more ...","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.seobility.net\/en\/wiki\/htaccess","og_locale":"en_US","og_type":"article","og_title":"What is .htaccess and what is it used for? - Seobility Wiki","og_description":".htaccess (hypertext access) is a powerful file whose function is to give instructions to the server. Learn more ...","og_url":"https:\/\/www.seobility.net\/en\/wiki\/htaccess","og_site_name":"Seobility","article_publisher":"https:\/\/www.facebook.com\/seobility.net\/","article_modified_time":"2025-02-26T09:23:44+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/www.seobility.net\/wp-content\/uploads\/2025\/06\/seobility-og-image.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@seobility_net","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"ScholarlyArticle","@id":"https:\/\/www.seobility.net\/en\/wiki\/htaccess#article","isPartOf":{"@id":"https:\/\/www.seobility.net\/en\/wiki\/htaccess"},"author":{"name":"Seobility Wiki Team","@id":"https:\/\/www.seobility.net\/en\/#\/schema\/person\/c838e66a3b46262b4c963df5cd5b2d8a"},"headline":".htaccess","datePublished":"2024-11-12T12:39:30+00:00","dateModified":"2025-02-26T09:23:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.seobility.net\/en\/wiki\/htaccess"},"wordCount":757,"commentCount":0,"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.seobility.net\/en\/wiki\/htaccess#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.seobility.net\/en\/wiki\/htaccess","url":"https:\/\/www.seobility.net\/en\/wiki\/htaccess","name":"What is .htaccess and what is it used for? - Seobility Wiki","isPartOf":{"@id":"https:\/\/www.seobility.net\/en\/#website"},"datePublished":"2024-11-12T12:39:30+00:00","dateModified":"2025-02-26T09:23:44+00:00","description":".htaccess (hypertext access) is a powerful file whose function is to give instructions to the server. Learn more ...","breadcrumb":{"@id":"https:\/\/www.seobility.net\/en\/wiki\/htaccess#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.seobility.net\/en\/wiki\/htaccess"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.seobility.net\/en\/wiki\/htaccess#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.seobility.net\/en\/"},{"@type":"ListItem","position":2,"name":"Wiki","item":"https:\/\/www.seobility.net\/en\/wiki"},{"@type":"ListItem","position":3,"name":".htaccess","item":"https:\/\/www.seobility.net\/en\/wp-json\/wp\/v2\/wiki\/30089"}]},{"@type":"WebSite","@id":"https:\/\/www.seobility.net\/en\/#website","url":"https:\/\/www.seobility.net\/en\/","name":"Seobility","description":"Online SEO Software &amp; Tools For Better Rankings","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.seobility.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.seobility.net\/en\/#\/schema\/person\/c838e66a3b46262b4c963df5cd5b2d8a","name":"Seobility Wiki Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.seobility.net\/wp-content\/uploads\/2025\/06\/Seobility-S-2025-150x150.png","url":"https:\/\/www.seobility.net\/wp-content\/uploads\/2025\/06\/Seobility-S-2025-150x150.png","contentUrl":"https:\/\/www.seobility.net\/wp-content\/uploads\/2025\/06\/Seobility-S-2025-150x150.png","caption":"Seobility Wiki Team"},"description":"The Seobility Wiki team consists of seasoned SEOs, digital marketing professionals, and business experts with combined hands-on experience in SEO, online marketing and web development. All our articles went through a multi-level editorial process to provide you with the best possible quality and truly helpful information. Learn more about the people behind the Seobility Wiki.","url":"https:\/\/www.seobility.net\/en\/blog\/author\/seobility-wiki-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.seobility.net\/en\/wp-json\/wp\/v2\/wiki\/30089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.seobility.net\/en\/wp-json\/wp\/v2\/wiki"}],"about":[{"href":"https:\/\/www.seobility.net\/en\/wp-json\/wp\/v2\/types\/wiki"}],"author":[{"embeddable":true,"href":"https:\/\/www.seobility.net\/en\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/www.seobility.net\/en\/wp-json\/wp\/v2\/comments?post=30089"}],"version-history":[{"count":0,"href":"https:\/\/www.seobility.net\/en\/wp-json\/wp\/v2\/wiki\/30089\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.seobility.net\/en\/wp-json\/wp\/v2\/media?parent=30089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}