WordPress Permalinks

WordPress Permalinks

So after setting up the Amasci Creative blog which is driven through WordPress, we decided to setup the Permalinks facility. The Permalinks facility for anyone who isn’t aware, is the ability to have clean links in the address so for example instead of the link being /blog/?p=$1 the link would be /blog/the-article-title/.

So with the permalinks setup in the WordPress admin panel, and allowing WordPress to write to the .htaccess file I thought it would be simple as clicking the ‘Save changes’ button. How wrong I was!

The permalinks would not work at all, just keep getting 404 errors, the .htaccess file was saved inside the /blog/ folder as per various instructions I had read. So after several different attempts, I stil was unable to get the permalinks to work correctly.

Research

I read various blogs, posts and did many searches in Google but couldn’t find any that seemed to work. I have to admit, I was very close to giving up at this stage, however, as is my nature I couldn’t let it lie and like a dog with a bone I kept on trying. Finally I decided to take a step back and approach this problem step by step.

Back to basics

Initially I decided to make sure that mod_reWrite was actually functioning and working correctly, and with some help from our web hosts, I put a simple RewriteRule inside the .htaccess file. This did work, so I could rule out any problem with the mod_reWrite module. Secondly I scrapped all of the WordPress htaccess code and decided to create my own RewriteRules. I managed to find a fantastic site - http://www.webmasterworld.com/forum92/4332.htm which broke down in simple terms all of the Mod_reWrite Regular Expressions. This made life much easier for creating the .htaccess code required.

Finally after several attempts I managed to create a successful .htaccess file which solved all my Permalink problems. The finally code looks like so:

RewriteRule ^home/amasci/public_html/blog/content/[^/.]+/ /blog/?p=$1 [nc] RewriteRule ^home/amasci/public_html/blog/page/[^/.]+/ /blog/?paged=$1 [nc]

The first line is the rewrite code for all the posts, categories and archives. The second rule works for the links to the older and new post pages.

My final tip is to check that your .htaccess file resides in the correct location, for some reason my file had to sit within the top level and did not function when inside the /blog/ folder. I had to reference the full path as you can see from the above note.

For those who do not wish to read the full article above. Here is a summary of steps taken:

  1. Check that mod_reWrite is actually on and working. A simple test for this is to create two simple html files – test1.html and test2.html and then to upload a .htaccess file with the following code:RewriteEngine on RewriteRule ^ /test1.html$ test2.html [L]
  2. If the standard WordPress rewrite code doesn’t work, try to create your own.
  3. Ensure that your .htaccess file is uploaded to the correct location and that you are referencing the correct paths. Sometimes they need to be full paths like in my example.
  4. Test, test, test and trial and error – keep persisting and you will finally get there!

Good luck!

Back to News