GoDaddy htaccess

November 23, 2007 · Print This Article

As I discussed in my previous article, I implemented a link directory using the WP Link Directory. Everything looked good until I tried to enable pretty permalinks. For those you don’t speak geek, pretty permalinks changes ugly urls like /?cat=9 to something like /open-source. You can see how one is easily identifiable and the other is incomprehensible. Well, most people like the one that can be understood. But I couldn’t get pretty permalinks to work in my directory.

The problem here arises because usually the htaccess fie is located in your root folder, but the WP Link Directory has its own htaccess folder within the ‘directory’ folder. The code I had, which was included with the WP Link Directory plugin was:

RewriteEngine on

RewriteRule ^categories/(.*)/(.*)$ index.php?cat=$1&page=$2 [QSA,L]
RewriteRule ^subcategories/(.*)/(.*)/(.*)$ index.php?cat=$1&scat=$2&page=$3 [QSA,L]

The ^ says to look within the folder that the htaccess is in. In this case, the ‘directory’ folder. This code will probably work for any other host, but not GoDaddy. As you’ll find if you Google ‘GoDaddy htaccess,’ many people have the same problem when trying to create pretty permalinks and GoDaddy is no help. I even called them, only to receive the same response I read on every forum where I looked for answers–”We don’t provide customer support for htaccess.” Well…the standard htaccess code wasn’t working, and I didn’t have a clue why. So I kept Googling for information, and kept trying every possible solution I came across. Everywhere I looked, everyone had the same issue, and most people suggested switching hosts. Well, I’m not one to give up that easily…

After a while, I came across a post that suggested that a certain line of code was vital to creating pretty permalinks using GoDaddy htaccess. This code is:

RewriteBase /

and it must be put before your rewrite rules. This code establishes the base to be your main url. So even the htaccess file is in your ‘directory’ folder, you’re specifying the base to be your main folder. Therefore, all other urls in the htaccess file need to reflect this. So, once you include this code, you must add the full extension to the rewrite rules. I’ll do my best to explain.

The original code was:

RewriteRule ^categories/(.*)/(.*)$ index.php?cat=$1&page=$2 [QSA,L]
RewriteRule ^subcategories/(.*)/(.*)/(.*)$ index.php?cat=$1&scat=$2&page=$3 [QSA,L]

Here, the index.php?cat= code is calling a php function from the WP Links Directory plugin, and pulling some dynamic content from the database. The index.php file is within a folder called ‘directory’. Therefore, we must change the htaccess code to:

RewriteRule ^categories/(.*)/(.*)$ directory/index.php?cat=$1&page=$2 [QSA,L]
RewriteRule ^subcategories/(.*)/(.*)/(.*)$ directory/index.php?cat=$1&scat=$2&page=$3 [QSA,L]

Adding the ‘directory” extensions tells the htaccess file to look for the index.php within the directory folder. So if you the pages you are creating the pretty permalinks for are in another folder, other than the root folder, you need your rewrite rule to include the extensions to take you into that folder.

If this is confusing, I understand. I used a lot of resources to research the solution to this problem. Here are a few of them:

HTML Source on Rewriting URLs
Easy Mod Rewrite
Mod_Rewrite ReWriteRule Generator

A couple good terms to search on Google are (just click and it will take you to the search page): apache mod rewrite, , mod rewrite tutorial and of course, GoDaddy htaccess.

So, here’s the final code I implemented to get the pretty permalinks working for WP Link Directory.

# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^categories/(.*)/(.*)$ directory/index.php?cat=$1&page=$2 [QSA,L]
RewriteRule ^subcategories/(.*)/(.*)/(.*)$ directory/index.php?cat=$1&scat=$2&page=$3 [QSA,L]
# END WordPress

Comments

3 Responses to “GoDaddy htaccess”

  1. fenerli on August 30th, 2008 8:33 pm

    cbf explaining but you misunderstood what the caret (^) was for in the first snippet, basically, it matches the start of the string, e.g. ^def matches “defghi” but not “abcdef”

  2. Krishna on September 3rd, 2008 11:29 am

    I have a multi-site hosted on godaddy with the root directory hosting one site and /hindupedia hosting another site (which is reached by the url: http://www.hindupedia.com). After trying alot of things on the web, I finally found a way to make this work.

    here is my .htaccess file’s contents

    AddHandler x-httpd-php5 .php
    AddHandler x-httpd-php .php4
    Options -MultiViews

    RewriteEngine On
    RewriteBase /
    RewriteRule ^hindupedia/eng/(.*)$ en/index.php?title=$1 [PT,L,QSA]

  3. Ralph on September 3rd, 2008 2:26 pm

    Thanks for posting that. A lot of people have trouble with GoDaddy hosting, so anything that helps is good!

Got something to say?