{"id":15775,"date":"2026-06-18T12:48:43","date_gmt":"2026-06-18T11:48:43","guid":{"rendered":"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/"},"modified":"2026-11-10T14:14:02","modified_gmt":"2026-11-10T13:14:02","slug":"what-is-an-htaccess-file-and-what-can-it-do","status":"publish","type":"post","link":"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/","title":{"rendered":"What Is an .htaccess File and What Can It Do?"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_87 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#What_Is_an_htaccess_File\" >What Is an .htaccess File?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Where_Is_the_htaccess_File_Located\" >Where Is the .htaccess File Located?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#How_to_find_it_in_cPanel\" >How to find it in cPanel<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#How_Does_an_htaccess_File_Work\" >How Does an .htaccess File Work?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#What_Can_an_htaccess_File_Do\" >What Can an .htaccess File Do?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#1_Redirect_visitors_to_a_new_URL\" >1. Redirect visitors to a new URL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#2_Rewrite_URLs_with_mod_rewrite\" >2. Rewrite URLs with mod_rewrite<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#3_Protect_a_directory_with_a_password\" >3. Protect a directory with a password<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#4_Restrict_access_to_selected_files_or_IP_addresses\" >4. Restrict access to selected files or IP addresses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#5_Display_a_custom_error_page\" >5. Display a custom error page<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#6_Redirect_HTTP_traffic_to_HTTPS\" >6. Redirect HTTP traffic to HTTPS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#7_Enable_browser_caching\" >7. Enable browser caching<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#8_Configure_compression\" >8. Configure compression<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#9_Prevent_image_hotlinking\" >9. Prevent image hotlinking<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#10_Set_MIME_types_and_other_file-handling_rules\" >10. Set MIME types and other file-handling rules<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#How_to_Edit_an_htaccess_File_Safely\" >How to Edit an .htaccess File Safely<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Using_htaccess_with_WordPress\" >Using .htaccess with WordPress<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Common_htaccess_Problems_and_How_to_Troubleshoot_Them\" >Common .htaccess Problems and How to Troubleshoot Them<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#500_Internal_Server_Error_after_editing\" >500 Internal Server Error after editing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Redirect_loop\" >Redirect loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Rules_appear_to_have_no_effect\" >Rules appear to have no effect<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#403_Forbidden_after_adding_an_access_rule\" >403 Forbidden after adding an access rule<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#WordPress_pages_return_404_errors\" >WordPress pages return 404 errors<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Does_htaccess_Work_on_Every_Web_Server\" >Does .htaccess Work on Every Web Server?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Shared_Hosting_and_htaccess_Support\" >Shared Hosting and .htaccess Support<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Shared_Hosting_with_cPanel\" >Shared Hosting with cPanel<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Can_I_delete_my_htaccess_file\" >Can I delete my .htaccess file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Can_I_have_more_than_one_htaccess_file\" >Can I have more than one .htaccess file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Does_htaccess_affect_website_speed\" >Does .htaccess affect website speed?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Do_I_need_htaccess_for_WordPress\" >Do I need .htaccess for WordPress?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Can_I_edit_htaccess_from_cPanel\" >Can I edit .htaccess from cPanel?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/da-manager.com\/blog\/what-is-an-htaccess-file-and-what-can-it-do\/#Final_Thoughts\" >Final Thoughts<\/a><\/li><\/ul><\/nav><\/div>\n<p>An <strong>.htaccess file<\/strong> is a configuration file that lets you control certain aspects of how an Apache web server handles requests for your website. It can be used to create redirects, manage URL rewriting, restrict access to files and directories, configure custom error pages and apply other directory-level settings.<\/p>\n<p>You may encounter this file when managing a website through cPanel, troubleshooting a WordPress site or changing how visitors reach particular pages. Used correctly, it is a practical way to manage website behaviour without editing the main Apache server configuration. Used incorrectly, however, a single invalid directive can make pages unavailable or trigger a 500 Internal Server Error.<\/p>\n<p>This guide explains what an .htaccess file does, where to find it, how to edit it safely and which common rules are useful. The examples are intended for Apache-compatible hosting. They will not work unchanged on every web server or hosting configuration.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_Is_an_htaccess_File\"><\/span>What Is an .htaccess File?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The name .htaccess is commonly understood as \u201chypertext access\u201d. It is a plain-text, per-directory configuration file supported by the Apache HTTP Server. It allows permitted Apache directives to be applied to a directory and, depending on the directive and configuration, its subdirectories.<\/p>\n<p>Unlike the main Apache configuration files, an .htaccess file can often be edited by a website owner who does not have administrator or root access to the server. This is one reason it is common on shared hosting accounts.<\/p>\n<p>Apache does not automatically apply every directive placed in this file. The server administrator must allow the relevant overrides, and the directive must be valid in that context. If overrides are disabled, Apache may ignore the file.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Where_Is_the_htaccess_File_Located\"><\/span>Where Is the .htaccess File Located?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The file is usually in the document root of the website. On many cPanel accounts this is <code>public_html<\/code>, although addon domains and subdomains may have their own document roots. A WordPress installation commonly has an .htaccess file in the directory containing its <code>wp-config.php<\/code> file and main WordPress folders.<\/p>\n<p>Because the filename begins with a dot, it is treated as a hidden file on many Unix-like systems. If you cannot see it, enable the option to show hidden files in your hosting File Manager or FTP client.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_find_it_in_cPanel\"><\/span>How to find it in cPanel<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li>Sign in to your hosting control panel and open File Manager.<\/li>\n<li>Open the website&#8217;s document root, often <code>public_html<\/code>.<\/li>\n<li>Use the File Manager settings to show hidden files (dotfiles).<\/li>\n<li>Look for <code>.htaccess<\/code>. If it does not exist, do not assume you must create one; first check whether your application or hosting provider manages the rules another way.<\/li>\n<\/ol>\n<p>You can also locate the file using an FTP client or SSH, if your hosting plan provides those options. Always confirm that you are editing the correct domain&#8217;s document root.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_Does_an_htaccess_File_Work\"><\/span>How Does an .htaccess File Work?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When Apache handles a request, it can read applicable .htaccess files in the directory path. Directives may affect the requested resource and, where inherited, resources in lower-level directories. A more specific file in a subdirectory can add to or override some parent-directory behaviour, depending on the directive.<\/p>\n<p>Whether Apache reads these files depends on its server configuration. The <code>AllowOverride<\/code> setting controls which classes of directives may be used in .htaccess files. With <code>AllowOverride None<\/code>, Apache does not use .htaccess files for that directory. Some hosting environments use <code>AllowOverrideList<\/code> to permit only selected directives. See the <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/howto\/htaccess.html\" target=\"_blank\" rel=\"noopener\">Apache guide to .htaccess files<\/a> for the server-side details.<\/p>\n<p>Changes usually take effect without restarting Apache because the file is checked during request processing. This convenience comes with a trade-off: complex rules can add overhead, and a syntax error or unsupported directive can cause an error response. If you administer the server, placing suitable rules in the main virtual-host configuration is generally more efficient than using .htaccess.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_Can_an_htaccess_File_Do\"><\/span>What Can an .htaccess File Do?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"1_Redirect_visitors_to_a_new_URL\"><\/span>1. Redirect visitors to a new URL<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Redirects send visitors and search engines from an old URL to a new one. A permanent redirect can be useful when a page has moved and the replacement should become the preferred destination.<\/p>\n<pre><code>Redirect 301 \/old-page.html https:\/\/www.example.com\/new-page\/<\/code><\/pre>\n<p>This uses Apache&#8217;s <code>mod_alias<\/code> module. For simple redirects, it is often clearer than writing a rewrite rule. Check the destination carefully and avoid redirect chains or loops. Do not add a redirect simply because a page returns a genuine 404; first decide whether a relevant replacement exists.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Rewrite_URLs_with_mod_rewrite\"><\/span>2. Rewrite URLs with mod_rewrite<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The <code>mod_rewrite<\/code> module can rewrite requests internally or redirect them externally based on conditions. Apache documents its directives and flags in the <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/mod\/mod_rewrite.html\" target=\"_blank\" rel=\"noopener\">mod_rewrite reference<\/a>. WordPress commonly uses rewrite rules to support readable permalink URLs.<\/p>\n<pre><code>RewriteEngine On\nRewriteRule ^old-section\/(.*)$ \/new-section\/$1 [R=301,L]<\/code><\/pre>\n<p>This example redirects matching paths from <code>\/old-section\/<\/code> to <code>\/new-section\/<\/code>. The rule assumes it is placed in a suitable per-directory context and should be tested against the actual URL structure before use. The <code>R=301<\/code> flag sends a permanent redirect, while <code>L<\/code> stops processing further rules in the current ruleset.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Protect_a_directory_with_a_password\"><\/span>3. Protect a directory with a password<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Apache can require a username and password before allowing access to a directory. This commonly uses an .htaccess file together with an .htpasswd file containing password hashes. Keep the password file outside the public document root wherever possible, and use HTTPS so credentials are not sent over an unencrypted connection.<\/p>\n<pre><code>AuthType Basic\nAuthName \"Restricted Area\"\nAuthUserFile \/home\/USERNAME\/.htpasswd\nRequire valid-user<\/code><\/pre>\n<p>Replace the example path with the actual absolute path supplied by your hosting provider. Create the password file using a trusted hosting tool or Apache&#8217;s supported password utility. Basic authentication is not a substitute for application-level security, and it should not be used over plain HTTP.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Restrict_access_to_selected_files_or_IP_addresses\"><\/span>4. Restrict access to selected files or IP addresses<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Apache 2.4 uses the <code>Require<\/code> authorisation directives, documented in the <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/mod\/mod_authz_core.html\" target=\"_blank\" rel=\"noopener\">mod_authz_core reference<\/a>. For example, to allow only a trusted IP address to access a protected directory, a rule may look like this:<\/p>\n<pre><code>Require ip 203.0.113.10<\/code><\/pre>\n<p><code>203.0.113.10<\/code> is an example address reserved for documentation. Replace it with the real trusted address. Be careful when restricting access: blocking your own IP or using an incorrect address can lock you out. Older examples using <code>Deny from<\/code> and <code>Allow from<\/code> belong to legacy access-control syntax and may require compatibility support on Apache 2.4.<\/p>\n<p>For sensitive files, prefer to prevent public access at the server or application level rather than relying on a broad collection of manually maintained rules.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"5_Display_a_custom_error_page\"><\/span>5. Display a custom error page<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can tell Apache to display a page you have created when a particular HTTP error occurs.<\/p>\n<pre><code>ErrorDocument 404 \/404.html\nErrorDocument 403 \/403.html<\/code><\/pre>\n<p>The paths are relative to the website&#8217;s document root. Make sure the custom pages exist and can be accessed, otherwise visitors may receive another error. A custom 404 page should help visitors find useful content, but it should still return the correct 404 HTTP status for a missing resource.<\/p>\n<p>For more detail, see our guide to <a href=\"https:\/\/da-manager.com\/blog\/how-to-configure-a-custom-error-page-on-your-hosting\/\">configuring a custom error page on your hosting<\/a>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"6_Redirect_HTTP_traffic_to_HTTPS\"><\/span>6. Redirect HTTP traffic to HTTPS<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If your website has a working SSL\/TLS certificate, you may use Apache rewrite rules to redirect HTTP requests to HTTPS. A common pattern is:<\/p>\n<pre><code>RewriteEngine On\nRewriteCond %{HTTPS} !=on\nRewriteRule ^ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [R=301,L]<\/code><\/pre>\n<p>This is a general example, not a universal drop-in rule. If your site is behind a reverse proxy or load balancer that terminates TLS, the server may see the connection from the proxy as HTTP. In that situation, a rule based only on <code>%{HTTPS}<\/code> can create redirect loops. Use the hosting provider&#8217;s documented configuration and avoid adding a second redirect if your control panel or application already enforces HTTPS.<\/p>\n<p>For a dedicated walkthrough, read <a href=\"https:\/\/da-manager.com\/blog\/how-to-force-https-redirect-in-htaccess\/\">how to force HTTPS redirects in .htaccess<\/a>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"7_Enable_browser_caching\"><\/span>7. Enable browser caching<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Apache&#8217;s <code>mod_expires<\/code> module can set expiry information for static resources such as images, stylesheets and scripts. This helps browsers reuse files instead of requesting them again on every visit.<\/p>\n<pre><code>&lt;IfModule mod_expires.c&gt;\n  ExpiresActive On\n  ExpiresByType image\/jpeg \"access plus 30 days\"\n  ExpiresByType image\/png \"access plus 30 days\"\n  ExpiresByType text\/css \"access plus 7 days\"\n  ExpiresByType application\/javascript \"access plus 7 days\"\n&lt;\/IfModule&gt;<\/code><\/pre>\n<p>Choose expiry periods that match how often your files change. If you use long caching periods, use versioned filenames or cache-busting techniques when you update assets. The rules have no effect if the required module is unavailable or disabled.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"8_Configure_compression\"><\/span>8. Configure compression<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Where the server supports it, Apache&#8217;s <code>mod_deflate<\/code> can compress suitable text-based responses before sending them to browsers. Compression can reduce transfer sizes, but should be configured with the server administrator&#8217;s guidance and tested for compatibility.<\/p>\n<p>See our separate guide on <a href=\"https:\/\/da-manager.com\/blog\/how-to-enable-gzip-in-htaccess\/\">enabling Gzip compression in .htaccess<\/a> for a focused explanation.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"9_Prevent_image_hotlinking\"><\/span>9. Prevent image hotlinking<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Hotlink protection attempts to stop other websites from embedding files directly from your server. It can reduce unwanted bandwidth use, but referer headers are not always present and can be modified or omitted. Rules that block every request without an expected referer may also affect legitimate visitors, privacy tools or search crawlers.<\/p>\n<p>If you enable hotlink protection, test image delivery from your own site, mobile browsers and any content delivery network you use. Many hosting control panels provide a hotlink protection interface that is easier to maintain.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"10_Set_MIME_types_and_other_file-handling_rules\"><\/span>10. Set MIME types and other file-handling rules<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Apache can associate file extensions with media types so that browsers and applications handle files appropriately. For example, the <code>AddType<\/code> directive can define a media type for a particular extension when the server configuration permits it.<\/p>\n<pre><code>AddType image\/webp .webp<\/code><\/pre>\n<p>Do not add MIME rules without checking whether Apache or your hosting environment already defines them. Incorrect content types can cause browsers to handle files unexpectedly.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Edit_an_htaccess_File_Safely\"><\/span>How to Edit an .htaccess File Safely<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li><strong>Make a backup.<\/strong> Download the current file before changing anything. Keep an untouched copy so you can restore it.<\/li>\n<li><strong>Use a plain-text editor.<\/strong> Avoid word processors that may insert formatting characters or change quotation marks.<\/li>\n<li><strong>Make one change at a time.<\/strong> This makes it easier to identify the rule responsible if something stops working.<\/li>\n<li><strong>Check the server environment.<\/strong> Confirm that the directive and module are supported and permitted by the host.<\/li>\n<li><strong>Save and test.<\/strong> Check the homepage, important pages, redirects, forms and any protected directories.<\/li>\n<li><strong>Restore the backup if necessary.<\/strong> If the site returns an error, restore the known-good file using File Manager or FTP.<\/li>\n<\/ol>\n<p>Do not change file permissions to make an .htaccess file executable. It is a text configuration file. Follow your hosting provider&#8217;s recommended ownership and permissions for website files.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Using_htaccess_with_WordPress\"><\/span>Using .htaccess with WordPress<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>On Apache-based hosting, WordPress can use .htaccess rewrite rules to support pretty permalinks. WordPress may create or update its standard rewrite section when you save permalink settings, provided the server allows it and the file is writable.<\/p>\n<p>If WordPress URLs suddenly return 404 errors, open the WordPress dashboard and visit <strong>Settings \u2192 Permalinks<\/strong>, then save the settings to refresh rewrite rules. Back up the file first if you plan to edit it manually. Do not replace the entire file with a generic example: plugins, security tools and hosting features may add their own rules.<\/p>\n<p>Some WordPress installations run on Nginx, which does not read .htaccess files. In that case, permalink rules must be configured in the Nginx server configuration or managed by the hosting provider. A WordPress site can also be served by LiteSpeed, which supports many Apache-style rules, but behaviour depends on its configuration.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Common_htaccess_Problems_and_How_to_Troubleshoot_Them\"><\/span>Common .htaccess Problems and How to Troubleshoot Them<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"500_Internal_Server_Error_after_editing\"><\/span>500 Internal Server Error after editing<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A syntax error, unsupported directive, missing module or disallowed override can cause a server error. Restore the backup first, then review the server error log and reintroduce changes one at a time. Our guide to <a href=\"https:\/\/da-manager.com\/blog\/how-to-fix-a-500-internal-server-error-on-your-hosting\/\">fixing a 500 Internal Server Error<\/a> explains the wider troubleshooting process.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Redirect_loop\"><\/span>Redirect loop<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>A loop can happen when multiple systems enforce HTTPS or when a reverse proxy makes Apache detect the wrong connection scheme. Remove duplicate redirect rules and follow the proxy or hosting provider&#8217;s instructions.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Rules_appear_to_have_no_effect\"><\/span>Rules appear to have no effect<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Check that the website is running on Apache or a compatible server, that .htaccess overrides are enabled, that the required module is loaded and that the file is in the correct document root. Also check for a more specific .htaccess file in a subdirectory.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"403_Forbidden_after_adding_an_access_rule\"><\/span>403 Forbidden after adding an access rule<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Review the <code>Require<\/code> rules, the client IP address Apache sees, file and directory permissions, and any security module or firewall rules. Remove the new restriction temporarily if it blocks legitimate access.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"WordPress_pages_return_404_errors\"><\/span>WordPress pages return 404 errors<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Refresh the permalink settings, check the WordPress rewrite section and confirm that the hosting server supports the rules being used. Do not assume every 404 requires a redirect; the cause may be a missing page or a routing configuration issue. See <a href=\"https:\/\/da-manager.com\/blog\/what-is-a-404-error-and-how-to-fix-it-on-your-website\/\">what a 404 error means and how to fix it<\/a> for further guidance.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Does_htaccess_Work_on_Every_Web_Server\"><\/span>Does .htaccess Work on Every Web Server?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>No. .htaccess is an Apache feature. Nginx does not process .htaccess files, and Microsoft IIS uses a different configuration system. LiteSpeed supports many Apache-compatible directives, but you should still confirm the exact features available on your hosting plan.<\/p>\n<p>Even on Apache, some hosting providers disable overrides or restrict which directives customers can use. If a rule does not work, ask your provider whether the directive and module are supported rather than repeatedly changing the file.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Shared_Hosting_and_htaccess_Support\"><\/span>Shared Hosting and .htaccess Support<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For website owners who need to manage redirects, WordPress permalinks and other Apache-compatible settings, a hosting account with a suitable control panel and documented server support can make routine administration easier. Before choosing a plan, confirm which web server is used and whether the directives you need are enabled.<\/p>\n<div class=\"damanager-product-card\">\n  <a href=\"https:\/\/my.da-manager.com\/store\/shared-hosting\" target=\"_blank\" rel=\"noopener\"><br \/>\n    <img decoding=\"async\" src=\"https:\/\/da-manager.com\/blog\/wp-content\/uploads\/2026\/05\/Da-Manager-Shared-Hosting-1-1.png\" alt=\"Shared web hosting plans with cPanel\" loading=\"lazy\" \/><br \/>\n  <\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Shared_Hosting_with_cPanel\"><\/span><a href=\"https:\/\/my.da-manager.com\/store\/shared-hosting\" target=\"_blank\" rel=\"noopener\">Shared Hosting with cPanel<\/a><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Explore hosting plans with cPanel, Apache-compatible website management, MySQL or MariaDB databases and backup features.<\/p>\n<p><a href=\"https:\/\/my.da-manager.com\/store\/shared-hosting\" target=\"_blank\" rel=\"noopener\">Explore Shared Hosting<\/a><\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_delete_my_htaccess_file\"><\/span>Can I delete my .htaccess file?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can remove it, but doing so may break redirects, access restrictions, caching rules or WordPress permalinks. Back it up and identify what depends on it before deleting it.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_have_more_than_one_htaccess_file\"><\/span>Can I have more than one .htaccess file?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes. Apache can read .htaccess files in different directories when overrides are enabled. Rules in a subdirectory can affect requests within that directory. Multiple files can make troubleshooting more complicated, so keep them organised.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_htaccess_affect_website_speed\"><\/span>Does .htaccess affect website speed?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It can add a small amount of request-processing overhead because Apache checks applicable files while handling requests. Large or complex rulesets can increase that overhead. For server administrators, putting suitable rules in the main server configuration is generally more efficient.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Do_I_need_htaccess_for_WordPress\"><\/span>Do I need .htaccess for WordPress?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Not always. WordPress commonly uses .htaccess for permalink rewriting on Apache, but Nginx uses server-level configuration instead. Your hosting environment determines which method applies.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_edit_htaccess_from_cPanel\"><\/span>Can I edit .htaccess from cPanel?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, if your hosting provider includes File Manager and grants access to the website files. Enable hidden files to see it, make a backup and use a plain-text editor.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Final_Thoughts\"><\/span>Final Thoughts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>An .htaccess file gives website owners a useful way to manage selected Apache settings without editing the server&#8217;s main configuration. It can handle redirects, URL rewriting, access control, custom error pages, caching and other tasks, provided the server allows the required directives.<\/p>\n<p>The safest approach is to understand what each rule does, back up the existing file, make one change at a time and test the result. If your server does not support .htaccess or a rule is ignored, check the hosting configuration before trying alternative directives.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understand what an .htaccess file is, where to find it and how to use it for redirects, HTTPS, access control, caching and troubleshooting on Apache hosting.<\/p>\n","protected":false},"author":16,"featured_media":16451,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mbp_gutenberg_autopost":false,"footnotes":""},"categories":[147],"tags":[4037,3971,333],"class_list":["post-15775","post","type-post","status-publish","format-standard","has-post-thumbnail","category-general","tag-htaccess","tag-apache","tag-cpanel"],"jetpack_featured_media_url":"https:\/\/da-manager.com\/blog\/wp-content\/uploads\/2026\/06\/what-is-htaccess-file-apache-guide.png","_links":{"self":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/15775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/comments?post=15775"}],"version-history":[{"count":2,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/15775\/revisions"}],"predecessor-version":[{"id":16453,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/15775\/revisions\/16453"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/media\/16451"}],"wp:attachment":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/media?parent=15775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/categories?post=15775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/tags?post=15775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}