wordpress permalink fix broken permalinks howto step by step!

October 12, 2010

How to fix broken permalinks in wordpress. Fixes blank pages and non-working links.

My problem was that links like this would work:

http://brakertech.com/?wordpress-permalink-fix/ but links like this would not:

http://brakertech.com/wordpress-permalink-fix/

Basically i thought the apache mod rewrite rule was working, just not accounting for the question mark.  However, after turning on heavy rewrite logging i noticed nothing was getting logged.  This was a big red flag that rewrites were not in fact on.  (how to set RewriteLog and RewriteLogLevel)

Eventually i realized my wordpress.conf file OptionIndexes and AllowOverride settings were denying all rewrites!  Here’s the fix on ubuntu and windows…

ensure your wordpress.conf files looks like this on ubuntu (check paths):

Alias /wordpress/ "/opt/wordpress-3.0.1-0/apps/wordpress/htdocs/"
Alias /wordpress "/opt/wordpress-3.0.1-0/apps/wordpress/htdocs"

    Options Indexes MultiViews FollowSymLinks
    AllowOverride FileInfo
    Order allow,deny
    Allow from all

or like this on windows (check paths):

Alias /wordpress/ "C:/Program Files/BitNami WAMPStack/apps/wordpress/htdocs/"
Alias /wordpress "C:/Program Files/BitNami WAMPStack/apps/wordpress/htdocs"

    Options Indexes MultiViews FollowSymLinks
    AllowOverride FileInfo
    Order allow,deny
    Allow from all

Now check your htaccess file..

Where’s my .htaccess file?

WordPress’s index.php and .htaccess files should be together in the directory indicated by the Blog address (URI) setting on your General Options page. Since the name of the file begins with a dot, the file may not be visible through an FTP client unless you change the preferences of the FTP tool to show all files, including the hidden files. Some hosts (e.g. Godaddy) may not show or allow you to edit .htaccess if you install WordPress through the Godaddy Hosting Connection installation.

Creating and editing (.htaccess)

If you do not already have a .htaccess file, create one. If you have shell or ssh access to the server, a simple touch .htaccess command will create the file. If you are using FTP to transfer files, create a file on your local computer, call it 1.htaccess, upload it to the root of your WordPress folder, and then rename it to .htaccess.

You can edit the .htaccess file by FTP, shell, or (possibly) your host’s control panel.

The following permalink rewrite code should be included in your .htaccess file:

# BEGIN WordPress

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

# END WordPress

If your .htaccess file contains errors that bring down your site (“Internal Server Error (500)”), you will need to use FTP or your host’s control panel to delete the rogue .htaccess file.

Permalinks without mod_rewrite

“Pretty” permalinks usually require mod_rewrite, and IIS (common on Windows servers) does not support mod_rewrite. (If you are using Apache 2.0.54, on Windows, mod_rewrite may work, provided it is enabled in apache\conf\httpd.conf.)

If you are using IIS 7 and have admin rights on your server, you can use Microsoft’s URL Rewrite Module instead. Though not completely compatible with mod_rewrite, it does support WordPress’s pretty permalinks. Once installed, open the web.config file in the WordPress folder and add the following rule to the system.webServer element


    
        
            
            
                
                
            
            
        
    

There’s a full installation guide on the IIS site. The module is available for x64 and x86 systems.

If this isn’t an option, you can try PATHINFO permalinks; put index.php/ at the start of your custom permalink structure:

 /index.php/%year%/%monthnum%/%day%/%postname%/

This option may not always work, especially in cases of WordPress running on IIS 6. To make this option work on IIS, add these 2 lines to a php.ini file and store that file in your webroot :

 cgi.fix_pathinfo = 1
 cgi.force_redirect = 0

Another solution exists using IIS’ custom 404 redirects. It requires that your web host allows you to add a custom 404 redirect, but it doesn’t require you to install any 3rd party mod_rewrite software and it also doesn’t require that your permalink structure begin with /index.php/.

Users of XAMPP (Windows): Some versions of XAMPP do not enable mod_rewrite by default (though it is compiled in Apache). To enable it — and thus enable WordPress to write the .htaccess file needed to create pretty permalinks — you must open apache/conf/httpd.conf and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound sign at the front of the line).