{"id":9300,"date":"2020-05-30T13:24:07","date_gmt":"2020-05-30T17:24:07","guid":{"rendered":"https:\/\/www.boldgrid.com\/support\/?p=9300"},"modified":"2021-01-28T13:47:02","modified_gmt":"2021-01-28T18:47:02","slug":"troubleshoot-htaccess-problems","status":"publish","type":"post","link":"https:\/\/www.boldgrid.com\/support\/troubleshooting\/troubleshoot-htaccess-problems\/","title":{"rendered":"How to troubleshoot .htaccess problems"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<?xml encoding=\"utf-8\" ?><html><body><p>The .htaccess file can be very useful, however it can also be time consuming and frustrating trying to track down issues within it. The goal of this guide is to provide you with resources to help identify and troubleshoot common .htaccess problems, as well as give a few tips that you can use to help should you run into problems related to this file.<\/p>\n<p><em>Note: To avoid having to troubleshoot problems with your .htaccess file by yourself, we recommend using a BoldGrid Official Partner web host for your <a href=\"https:\/\/www.boldgrid.com\/wordpress-hosting\/\">WordPress hosting<\/a> needs. They are certified WordPress and BoldGrid experts, and can make issues like this go away in a flash. Back to the regularly scheduled article!<\/em><\/p>\n<h2 id=\"the-htaccess-file\">The .htaccess file<\/h2>\n<p>The .htaccess file is a configuration file for web servers that run the Apache Web Server Software. When an .htaccess file, or Hypertext Access File, is detected within a web site&rsquo;s document root, it is then loaded, and any rules in the file are executed. The .htaccess file is extremely useful for making configuration changes to the Apache service that only apply to the directory (and its subdirectories) in which they are added. You can perform redirects, change a sites header, and create SEO Friendly URL&rsquo;s that exclude the file extension, and add a trailing slash (\/) making the link appear like a folder, rather than a file.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"alert alert-info\" role=\"alert\">In Linux, any file that begins with a dot (.) is treated as hidden. When a file is hidden it can not been seen with a file browser by default. In most cases, you can view the file browser&rsquo;s settings, and ensure it is set to allow hidden files to be viewed.<\/div>\n<p>The most common error that you will see with .htaccess file problems is a 500, or Internal Server Error, as seen below.<br>\n<a href=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9308 size-large\" src=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error-1024x244.jpg\" alt=\"\" width=\"1024\" height=\"244\" srcset=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error-1024x244.jpg 1024w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error-300x71.jpg 300w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error-768x183.jpg 768w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error-250x60.jpg 250w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error-550x131.jpg 550w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error-800x190.jpg 800w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error-756x180.jpg 756w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2017\/08\/9300-01-500error.jpg 1109w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"common-reasons-htaccess-is-not-working\">Common Reasons .htaccess is not working<\/h2>\n<p>&nbsp;<\/p>\n<h3 id=\"possible-typos\">Possible Typos<\/h3>\n<p>If you are replacing, or recreating the file, then you must be sure the filename is correct and that it begins with a period &ldquo;.&rdquo; If the period is not at the beginning, Apache will ignore the file &ndash; this will occur if it is misspelled as well.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"rule-location\">Rule Location<\/h3>\n<p>Some rules will affect others. If you have added a rule, and it is not working you may want to try and move it above any directives you have already, or even to the top of the file to see if that works. The reason being when .htaccess it read by Apache, it does so from top to bottom, and some rules may be conflicting with what you are attempting to add.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"conflicting-htaccess-files\">Conflicting .htaccess files<\/h3>\n<p>An .htaccess file&rsquo;s rules apply to the directory that it is in, as well as any sub-directories that are within that directory. Because of this, an .htaccess file in a higher level directory can affect your site files as well. An easy way to narrow down whether this is a cause would be to rename the .htaccess file, which will effectively disable it.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"incorrect-syntax\">Incorrect Syntax<\/h3>\n<p>The most common issues with .htaccess files are syntax related. Syntax errors in .htaccess will cause 500 errors in Apache. Make sure you check the file to ensure you are using the correct syntax for the directive in question.<\/p>\n<p>&nbsp;<\/p>\n<p>You can reference <a href=\"https:\/\/httpd.apache.org\/docs\/current\/howto\/htaccess.html\" target=\"_blank\" rel=\"noopener noreferrer\">Apaches .htaccess documentation<\/a> for further information.<\/p>\n<h2 id=\"how-to-troubleshoot-htaccess-issues\">How to troubleshoot .htaccess issues<\/h2>\n<p>&nbsp;<\/p>\n<h3 id=\"use-an-htaccess-validator\">Use an .htaccess validator<\/h3>\n<p>You can use tools such as <a href=\"http:\/\/www.htaccesscheck.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.htaccesscheck.com\/<\/a> to validate and check your syntax. This is very useful in identifying any errors that may cause problems.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"check-apache-error-logs\">Check Apache Error Logs<\/h3>\n<p>If you make changes and your site breaks, you can check the Apache error log, which is normally located at \/var\/log\/apache2\/error_log<\/p>\n<p>&nbsp;<\/p>\n<p>For example, if I added a . to the bottom of an .htaccess file, and when the site loads, this error can be found within the Apache error log:<br>\nInvalid command &lsquo;.&rsquo;, perhaps misspelled or defined by a module not included in the server configuration<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"debugging-with-apache-configuration\">Debugging with Apache Configuration<\/h3>\n<p>If you have access to the httpd.conf file, you can add your .htaccess file inside of a directory tag, and it will allow any errors to be logged, which will point out the issues you may be having quicker.<\/p>\n<p>&nbsp;<\/p>\n<p>Here is a sample of the configuration you can use:<\/p>\n<pre># BEGIN WordPress\r\n \r\n RewriteEngine On\r\n RewriteBase \/\r\n RewriteRule ^index\\.php$ - [L]\r\n RewriteCond %{REQUEST_FILENAME} !-f\r\n RewriteCond %{REQUEST_FILENAME} !-d\r\n RewriteRule . \/index.php [L]\r\n \r\n# END WordPress\r\n.\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The Apache error log would then point directly to the line that has the error, helping troubleshooting by pointing to the exact location of the issue. In this case, it would be a stray &ldquo;.&rdquo; at the end of the file which could easily be overlooked.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"enable-mod_rewrite-logs\">Enable Mod_Rewrite Logs<\/h3>\n<p>If you&rsquo;re using Apache&rsquo;s mod_rewrite module, you can enable the rewrite log to give you details about any issues you may have. To accomplish this, you will need access to the Apache configuration file.<\/p>\n<p>&nbsp;<\/p>\n<p>You can find out more about enabling this log in the <a href=\"http:\/\/httpd.apache.org\/docs\/2.4\/mod\/mod_rewrite.html#logging\" target=\"_blank\" rel=\"noopener noreferrer\">Apache documentation<\/a><\/p>\n<p>&nbsp;<\/p>\n<div class=\"alert alert-info\" role=\"alert\">There is a direct correlation between the trace log level you define, and the speed of Apache&rsquo;s response. The larger the number is, that you use for trace logs, the slower your sites will load. Because of this, it is recommended to keep this disabled unless troubleshooting a specific issue.<\/div>\n<p>&nbsp;<\/p>\n<h3 id=\"404-errors--permalink-settings\">404 Errors \/ Permalink Settings<\/h3>\n<p>One of the most common errors when dealing with WordPress Permalink problems is a Server Level 404 Error. This is fixed by either adding back the permalink rewrites in .htaccess, or navigating to Settings &gt; Permalinks and clicking save.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"not-generated-during-inspirations\">Not Generated During Inspirations<\/h3>\n<p>If your .htaccess file is not automatically generated during Inspirations, then there is likely an issue with your file permissions, or your web server&rsquo;s Apache configuration.<\/p>\n<h2 id=\"default-wordpress-htaccess\">Default WordPress .htaccess<\/h2>\n<p>There are multiple configurations for permalinks, as you have the option to change or customize them to suit your needs. Here are the default .htaccess files for WordPress single and multisite uses:<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"wordpress-single-site\">WordPress Single Site:<\/h3>\n<pre># BEGIN WordPress\r\n\r\nRewriteEngine On\r\nRewriteBase \/\r\nRewriteRule ^index\\.php$ - [L]\r\nRewriteCond %{REQUEST_FILENAME} !-f\r\nRewriteCond %{REQUEST_FILENAME} !-d\r\nRewriteRule . \/index.php [L]\r\n\r\n# END WordPress<\/pre>\n<p>&nbsp;<\/p>\n<h3 id=\"wordpress-multisite\">WordPress Multisite<\/h3>\n<h4 id=\"subfolder-example\">Subfolder Example<\/h4>\n<pre>RewriteEngine On\r\nRewriteBase \/\r\nRewriteRule ^index\\.php$ - [L]\r\n\r\n# add a trailing slash to \/wp-admin\r\nRewriteRule ^([_0-9a-zA-Z-]+\/)?wp-admin$ $1wp-admin\/ [R=301,L]\r\n\r\nRewriteCond %{REQUEST_FILENAME} -f [OR]\r\nRewriteCond %{REQUEST_FILENAME} -d\r\nRewriteRule ^ - [L]\r\nRewriteRule ^([_0-9a-zA-Z-]+\/)?(wp-(content|admin|includes).*) $2 [L]\r\nRewriteRule ^([_0-9a-zA-Z-]+\/)?(.*\\.php)$ $2 [L]\r\nRewriteRule . index.php [L]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4 id=\"subdomain-example\">SubDomain Example<\/h4>\n<pre>RewriteEngine On\r\nRewriteBase \/\r\nRewriteRule ^index\\.php$ - [L]\r\n\r\n# add a trailing slash to \/wp-admin\r\nRewriteRule ^wp-admin$ wp-admin\/ [R=301,L]\r\n\r\nRewriteCond %{REQUEST_FILENAME} -f [OR]\r\nRewriteCond %{REQUEST_FILENAME} -d\r\nRewriteRule ^ - [L]\r\nRewriteRule ^(wp-(content|admin|includes).*) $1 [L]\r\nRewriteRule ^(.*\\.php)$ $1 [L]\r\nRewriteRule . index.php [L]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3 id=\"htaccess-rules-for-nginx\">.htaccess rules for NGINX<\/h3>\n<p>Since NGINX does not use an .htaccess file, you would have to apply your rewrites directly to the configuration. To accomplish this, you can use a converter tool, such as https:\/\/winginx.com\/en\/htaccess which will give you the correct syntax to use for NGINX. You would then apply this to your NGINX configuration file.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"alert alert-info\" role=\"alert\">If you are unsure of how to make these types of changes, or running into issues attempting, then it is recommended to contact your host for additional information.<\/div>\n<p>&nbsp;<\/p>\n<p>Congratulations! With the troubleshooting techniques provided, you now have more information as well as some common steps to help solve common .htaccess problems. Looking for more? We have tons of other WordPress tutorials and articles for you to check out!<\/p>\n<\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>The .htaccess file can be very useful, however it can also be time consuming and frustrating trying to track down issues within it. The goal of this guide is to provide you with resources to help identify and troubleshoot common .htaccess problems, as well as give a few tips that you can use to help [&hellip;]<\/p>\n","protected":false},"author":529,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"bgseo_title":"How to troubleshoot .htaccess problems - BoldGrid","bgseo_description":"The goal of this guide is to provide you with resources and common practices to help identify and troubleshoot .htaccess problems.","bgseo_robots_index":"index","bgseo_robots_follow":"follow","footnotes":""},"categories":[74],"tags":[],"class_list":["post-9300","post","type-post","status-publish","format-standard","hentry","category-troubleshooting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts\/9300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/users\/529"}],"replies":[{"embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/comments?post=9300"}],"version-history":[{"count":13,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts\/9300\/revisions"}],"predecessor-version":[{"id":33339,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts\/9300\/revisions\/33339"}],"wp:attachment":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/media?parent=9300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/categories?post=9300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/tags?post=9300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}