{"id":1038,"date":"2016-03-30T23:21:20","date_gmt":"2016-03-31T06:21:20","guid":{"rendered":"https:\/\/www.1keydata.com\/blog\/?p=1038"},"modified":"2016-04-01T19:45:11","modified_gmt":"2016-04-02T02:45:11","slug":"wordpress-permalink-stops-working","status":"publish","type":"post","link":"https:\/\/www.1keydata.com\/blog\/wordpress-permalink-stops-working.html","title":{"rendered":"WordPress Permalink Stops Working"},"content":{"rendered":"<p>I recently migrated to a new Linux server with a different version of Apache, and for a while I could not get the WordPress permalinks to work. After a lot of trial and error, I figured out what the problem was, and I hope the information I share here will help someone in the future.<\/p>\n<p>Below are the relevant system information:<br \/>\nOS: Ubuntu 14.04 LTS<br \/>\nWeb Server: Apache 2.4.18<\/p>\n<h3>What was the initial symptom?<\/h3>\n<p>The home page of the blog loaded OK. However, when I clicked on any link to go into any post, category, or month, I got a 404 error.<\/p>\n<p>For those of you who wants to know the answer right away without reading through my journey of getting there, go to the <a href=\"#fix\">Fix<\/a> section.<\/p>\n<h3>Things I tried<\/h3>\n<p>I tried a number of ways to resolve this issue. They were as follows:<\/p>\n<p><!--more-->1. Disabled all plugins. This did not help. The same 404&#8217;s still appeared after all the plugins were disabled. At this point, I concluded the plugins were not the issue.<\/p>\n<p>2. Used a default theme. This did not help. In fact, I tried several different themes, and I kept getting the same error regardless of which theme I used. So, theme was not the issue, either.<\/p>\n<p>3. Changed the permalinks to the default URL. This change fixed the issue! However, this is not a viable solution as I have no interest of changing my blog URL to something like https:\/\/www.1keydata.com\/blog\/?p=200. However, this did tell me something useful&#8211;the issue was related to rewriting the URL.<\/p>\n<p>4. Changed the permalink to include index.php as part of the URL. For example, https:\/\/www.1keydata.com\/blog\/index.php\/2016\/03\/february-2016-browser-market-share.html. This change also fixed the issue. However, this is not an ideal solution because I&#8217;d have to put 301 redirects on all my prior posts, category pages, tag pages, and month pages to eliminate the 404&#8217;s. This was not something I wanted to go through.<\/p>\n<p>At this point, this appeared to be some kind of Apache URL rewrite issue. But I already have the appropriate .htaccess file in the \/blog directory. So what could be going on? My theory was that for some reason Apache was not set up to read .htaccess files.<\/p>\n<p>To fix this, my first try was to add &#8220;AllowOverride All&#8221; to apache2.conf under the appropriate directory. However, when I did this and restarted Apache, I saw a 500 error when I visit the website. Unfortunately, this method did not work.<\/p>\n<p>Then, I remembered that whatever you can put in .htaccess, you can also put it in the server config file. This led me to the fix:<\/p>\n<h3>Fix<\/h3>\n<p><a name=\"fix\"><\/a>Take the .htaccess content that WordPress wants you to use, which should look like the following:<\/p>\n<div style=\"background: #CCC; padding: 10px;\">&lt;IfModule mod_rewrite.c&gt;<br \/>\nRewriteEngine On<br \/>\nRewriteBase \/blog\/<br \/>\nRewriteRule ^index\\.php$ &#8211; [L]<br \/>\nRewriteCond %{REQUEST_FILENAME} !-f<br \/>\nRewriteCond %{REQUEST_FILENAME} !-d<br \/>\nRewriteRule . \/blog\/index.php [L]<br \/>\n&lt;\/IfModule&gt;<\/div>\n<p>&nbsp;<br \/>\npaste this content into your example.com.conf in \/etc\/apache2 using your favorite Linux text editor such as vi, emacs, or nano. After that, restart apache by typing in<\/p>\n<div style=\"background: #CCC; padding: 10px;\">sudo service apache2 restart<\/div>\n<p>&nbsp;<br \/>\nViola! My desired permalinks now render okay! This is a fairly elegant solution because it adheres with what Apache recommends (not using .htaccess file). Also, it is a good idea not to have the &#8220;AllowOverride All&#8221; directive on because when it is on, Apache will first search for the presence of .htaccess at each directory level. For example, if your URL is<\/p>\n<p>www.example.com\/123\/456\/789.html<\/p>\n<p>Apache will look for the following .htaccess files:<\/p>\n<p>www.example.com\/.htaccess<br \/>\nwww.example.com\/123\/.htaccess<br \/>\nwww.example.com\/123\/456\/.htaccess<\/p>\n<p>Not having to go through these files improves Apache&#8217;s performance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently migrated to a new Linux server with a different version of Apache, and for a while I could not get the WordPress permalinks to work. After a lot of trial and error, I figured out what the problem was, and I hope the information I share here will help someone in the future. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[390],"_links":{"self":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts\/1038"}],"collection":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/comments?post=1038"}],"version-history":[{"count":18,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts\/1038\/revisions"}],"predecessor-version":[{"id":1056,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts\/1038\/revisions\/1056"}],"wp:attachment":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/media?parent=1038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/categories?post=1038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/tags?post=1038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}