WordPress Permalink Migration: Windows to Linux

WordPress Permalink Migration - Dashboard
When I migrated my WordPress blog from a Microsoft Windows server to a GoDaddy Linux server, everything seemed to work better – with the exception of permalinks. Some of the permalinks on sites other than mine, for example http://www.kenmorico.com/index.php/2009/07/recognize-passed-loved-ones-using-social-media/ still had the index.php portion in the url. When users clicked the link on the new server they got a “No input file specified.” message. Permalink redirects should have been handled by WordPress. The standard  .htaccess file that WordPress creates doesn’t solve for this.

The stock install writes an .htaccess file like this (assuming a “blog” subfolder):

# BEGIN WordPress

 

RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

 

# END WordPress

{REQUEST_FILENAME}

The {REQUEST_FILENAME} seemed to blow up when it saw /index.php/ with the trailing slash and erred with the “No input file specified.” message. I determined that I needed to write a redirect rule BEFORE the {REQUEST_FILENAME} code took effect. Basically I needed the server to read the incoming url and see if it had the trailing slash after the index.php. If it did, redirect the url to a normal WordPress url on my existing site. The 301 tells Web servers that the redirect is permanent and all PageRank should be applied to the new location. 301 status messages also pass along the referrer – important for your web stats.

RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_URI} ^.*/index.php/.* [NC]
RewriteRule ^index\.php/(.*)$ https://kenmorico.com/$1 [R=301,L]

.htaccess files can really jack up your site, so be sure to make a backup before you mess with this file. Also, check out the mod_rewrite documentation on the Apache Website. To sum up, you only need this adjustment if there are links on the web pointing to the old “PATHINFO” version of your url. WordPress handles all the links within the blog just fine.

Benefits of Linux Hosting and Mod-Rewrite

One of the main benefits to migrating WordPress on Linux was being able to use the “pretty” permalinks with Apache’s mod-rewrite. With links getting longer and longer, you need mod-rewrite to shorten the links. In my experience, blog posts need the title of the post in the url for better search engine ranking. Saving 9 characters from the URL by removing “index.php” helps a lot and is much easier for people to read. Mod-rewrite rules are everywhere on the Internet (see above) and there’s always a post describing to redirect or rewrite with flair. Windows redirects are cumbersome and might require special software installations. The rewrite rules are NOT seamlessly transferable.

WordPress Hosting Differences Between Windows and Linux

When I had WordPress on the windows server at CrystalTech, I could never get email notifications from the WordPress blog. The server setup had a hard time communicating with the PHP mail function. WordPress on Linux works fine using the standard PHP mail function, like you would expect with a Linux / PHP / MySQL setup for WordPress. Truth be told, I haven’t had real problems with custom PHP code I wrote hosted on Windows servers using the PHP mail function, but communicating with Microsoft exchange using PHP can be a problem. Like most sites, you should go on one platform or the other and save headaches. You’ll also find that Linux hosting is cheaper than Windows hosting.

404 Pages

A final tip: make sure you check your Google Webmaster Tools for 404 pages. It finds broken links on sites that are not your own. Fixing 404 pages brings more traffic to your site and helps other webmasters look good when their links function.

Resources

Comments From Facebook Users