Apr

24

Drupal – Getting Clean URLs To Work With GoDaddy Shared Hosting

If you're using GoDaddy for your web hosting and you've installed Drupal on your shared hosting (Economy, Deluxe, or Unlimited hosting plans), then you may have run into the issue where you can't enable Clean URLs for Drupal. Fortunately, there's an easy fix. Unfortunately, the fix is so easy, I'm not sure why GoDaddy hasn't fixed this.

In your FTP client or the file browser in GoDaddy's tools, navigate to the root where your Drupal instance has been installed and look for your .htaccess file. Look for this important line, noted in red:

#
# Apache/PHP/Drupal settings:
#
...

# Various rewrite rules.
<IfModule mod_rewrite.c>
 ...

 # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
 # VirtualDocumentRoot and the rewrite rules are not working properly.
 # For example if your site is at http://example.com/drupal uncomment and
 # modify the following line:
 # RewriteBase /drupal
 #
 # If your site is running in a VirtualDocumentRoot at http://example.com/,
 # uncomment the following line:
 # RewriteBase /

...
</IfModule>

# $Id: .htaccess,v 1.90.2.5 2010/02/02 07:25:22 dries Exp $

All you have to do here is delete the # in front of that line, which will uncomment that directive and allow Drupal to be able to successfully manage your site with Clean URLs. You will, however, have to enable it in your site configuration.

Don't forget to save your file after editing and best practice is that you should probably backup the .htaccess file before editing it.

See how easy that was? I wonder why GoDaddy hasn't fixed that yet. *shrug*

Sources: http://drupal.org/node/89089, http://drupal.org/node/364511

Note: I'm aware that there are several places on the web that this is explained, but it's important for GoDaddy users to know if they are using Drupal, so I thought I would add one more instance of this information to help spread the knowledge.


  • email
  • Print
  • Google Bookmarks
  • Twitter
  • Facebook
  • MySpace
  • Digg
  • LinkedIn
  • Slashdot

Apr

4

WordPress – Making Yoast Breadcrumbs Behave Like A Good Boy

I mentioned in a recent post (okay, very recent) that Yoast Breadcrumbs needed some tweaking to get it to behave the way I wanted it to. This post will outline the changes that I made to my theme to get Yoast Breadcrumbs to cooperate.

First, check to see if the plugin is installed and enabled. If it is, let's get the output from the plugin:

<?php
    if(function_exists('yoast_breadcrumb'))
    {
        $breadcrumbs = yoast_breadcrumb("", "", false);
        ...
    } // end if test
?>

The first issue that I ran into is that even though I had Separator between breadcrumbs in the configuration set to &amp;raquo;, it was still throwing out » (rather than the HTML entity). To force that, I added this line:

$breadcrumbs = str_replace("»", "&raquo;", $breadcrumbs);

Since I was using a static page as my homepage and since I had all my breadcrumbs prefaced with a hyperlink to KennyCarlile.com (linked to root), I didn't want it to appear as KennyCarlile.com » About. That would just be silly. But, I wanted that root link to preface all my other pages, so I just wanted to hide the » About part.

        if(is_front_page())
        {
            echo '<a href="/">' . $breadcrumbs .
                '</a> &raquo; ' .
                '<strong>About</strong>';
        } // end if test

Now we get into the real voodoo and black magic. All other cases should be for pages where we want to display the full breadcrumb. For some reason, it was adding multiple links on occasion, depending on where it was in the site hierarchy. To handle that, I split the breadcrumb into an array, then looked at each position in the array and compared it to the next one to see if they are the same. If they are different, add it to a new array. If they are the same, ignore it and continue on.

        else
        {
            // split breadcrumb string into array
            $linksArr = split('&raquo;', $breadcrumbs);
            $newLinksArr = array(); // new links array
            $lastIndex = count($linksArr) - 1;

            // look through the links
            for($i = 0; $i <= $lastIndex; $i++)
            {
                // if 2 in a row are NOT the same...
                if(trim($linksArr[$i]) != trim($linksArr[$i + 1]))
                {
                    // ...add to the new array
                    $newLinksArr[] = $linksArr[$i];
                } // end if test
            } // end for loop

Okay, no more duplicate breadcrumb links, but now it's still linking the final breadcrumb. I want to display the page that I'm on in the breadcrumb, but it doesn't need to be a link. Why link to yourself, right? Here's some real voodoo. This is your cue to take off running if you hate regular expressions. :)

            // get the new array size
            $lastIndex = count($newLinksArr) - 1;

            // looking to extract the text from a hyperlink,
            // replace it with the same word in bold
            $pattern = '/(.*>)([^<]*)(<.*)/';
            $replace = '<strong>$2</strong>';
            $newLinksArr[$lastIndex] = preg_replace($pattern,
                                            $replace,
                                            $newLinksArr[$lastIndex]);

Cool, no more link for the page that we are on. Now we just need to turn that array back into a string and print that string to the output stream and we're done!

            // return links array to string
            $breadcrumbs = implode(" &raquo; ", $newLinksArr);    

            echo $breadcrumbs;
        } // end else test
    } // end if test
?>

That's how I solved the limitations of the Yoast Breadcrumbs plugin. I should say that I'm very impressed by what Yoast was able to do, but it just wasn't quite what I needed. I'm sure there are plenty of other ways to do this, possibly easier ones too, but this is my solution.

Here's the full code that I added to my theme to handle the breadcrumbs correctly:

<?php
    if(function_exists('yoast_breadcrumb'))
    {
        $breadcrumbs = yoast_breadcrumb("", "", false);
        $breadcrumbs = str_replace("»", "&raquo;", $breadcrumbs);

        if(is_front_page())
        {
            echo '<a href="/">' . $breadcrumbs .
                '</a> &raquo; ' .
                '<strong>About</strong>';
        } // end if test
        else
        {
            // split breadcrumb string into array
            $linksArr = split('&raquo;', $breadcrumbs);
            $newLinksArr = array(); // new links array
            $lastIndex = count($linksArr) - 1;

            // look through the links
            for($i = 0; $i <= $lastIndex; $i++)
            {
                // if 2 in a row are NOT the same...
                if(trim($linksArr[$i]) != trim($linksArr[$i + 1]))
                {
                    // ...add to the new array
                    $newLinksArr[] = $linksArr[$i];
                } // end if test
            } // end for loop

            // get the new array size
            $lastIndex = count($newLinksArr) - 1;

            // looking to extract the text from a hyperlink,
            // replace it with the same word in bold
            $pattern = '/(.*>)([^<]*)(<.*)/';
            $replace = '<strong>$2</strong>';
            $newLinksArr[$lastIndex] = preg_replace($pattern,
                                            $replace,
                                            $newLinksArr[$lastIndex]);

            // return links array to string
            $breadcrumbs = implode(" &raquo; ", $newLinksArr);    

            echo $breadcrumbs;
        } // end else test
    } // end if test
?>

  • email
  • Print
  • Google Bookmarks
  • Twitter
  • Facebook
  • MySpace
  • Digg
  • LinkedIn
  • Slashdot

Apr

3

WordPress – Displaying Custom-Formatted Links To Page Children

This is just a quick and easy tip, but it was harder to find the answer to than I would have expected. (…or maybe I just didn't appease the Google Gods correctly when searching.)

If you have a page hierarchy within your WordPress site and you want to display (such as in the sidebar) the immediate children of the current page that you're on, here's the code to do it.

<?php
    // will display the subpages of this top level page
    $children = wp_list_pages("title_li=&child_of=" . $post->ID . "&echo=0");
    if ($children)
    {
        // custom formatting goes here, just print
        // $children when you want to render the link
        echo '<div id="pagelist">' . "\n";
        echo "<ul>\n$children\n</ul>\n";
        echo '</div> <!-- end div id="pagelist" -->' . "\n";
    } // end if test
?>

Please note that this method only lets you custom format the display around the actual link. wp_list_pages() will return the text with the anchor link already wrapped around it. I haven't dug into how to further format the link.

I hope that helps!


  • email
  • Print
  • Google Bookmarks
  • Twitter
  • Facebook
  • MySpace
  • Digg
  • LinkedIn
  • Slashdot

Apr

3

Yet Another List Of Recommended WordPress Plugins

I know there have been a zillion and a half posts written about the best plugins for WordPress, but I thought I would throw my hat in the ring and offer up my favorites. Some are the common ones that you'll find on many other lists, but some are ones that I've had to dig for to fulfill a unique need that I had. If you're a WordPress veteran, maybe you'll find a gem in this list that you apply to your site. If you're new to WordPress, you'll likely find many of the plugins on this list that you'll want to add to your site.

Akismet – There's a reason why this plugin comes stock with WordPress. If you allow users to comment on your site, you definitely want to use Askimet to help prevent spam. It's not perfect, but it's really, really good. If you have a very high traffic site, you may want to incorporate some additional spam protection, like a CAPTCHA or some other means, but Askimet does a pretty good job for most needs. The only gotcha is that you need to request an API key from Askimet to use it. The good news is that you can use that key across many WP sites.

All In One SEO Pack – If you want to improve the Search Engine Optimization (SEO) for your site, this plugin provides a lot of enhancements for you. This plugin offers a lot of customization, but, frankly, I mostly leave it as is. I'll fill in the meta description and meta keywords and then leave the rest as is.

Audio Player – I didn't like the default WP hosting functionality for audio files as I wanted to be able to have a small inline player. After a little bit of digging, I found Audio Player and I was quite impressed with the visual customizations that you can do through the admin interface to make it fit with your theme. Be sure to check out this plugin if you want to host playable (not just downloadable) music or podcasts.

Dagon Design Sitemap Generator – While the Google XML Sitemaps plugin generates a sitemap.xml file for search engines to read, it's HTML sitemap is less than desirable. This plugin lets you create a page and then drop a code anywhere in the page to render a customizable, paged sitemap.

Enable Media Replace – Recently, I needed to replace some images on my photography site, 528Digital.com. I was disappointed to learn that my options were to either manually FTP and replace the image (maintaining the same file dimensions and name manually) or to delete the image, upload a new one, and then re-insert that new image into the post. That was unacceptable to me. Thankfully, I ran into this plugin that just adds one little bit of functionality to the Edit mode in managing your media that allows you to replace the file by uploading a new one. It maintains the same references, filename, etc., so you don't have to make any further edits. Just replace and you're done!

Exec-PHP – To be honest, I'm not sure if I can remember an instance when I've used this, except for with PicasaWebScraper, but I like to have it installed for the case when I might need it some day. It allows you to put executable PHP into the body of your posts or pages. This is great when you want to use WP as more of a content management system and you need to inject some dynamic functionality. You should, however, be careful with this plugin if you have non-technical users as they could cause a problem or break some PHP code written by someone else when editing content. EDIT: I recently found that runPHP has some of the features that Exec-PHP lacks, such as enabling for a specific page/post and you can specify access by role.

Google XML Sitemaps – This plugin generates an XML sitemap of your site's content for search engines to read. This helps with content indexing for search engines and you can leverage it using Google's Webmaster Tools to check for broken links.

Improved Include Page – I only used this plugin briefly before I changed my mind on how I wanted to do something, but it allows you to include page content within your theme. For example, you might want a small block of a theme that appears on every page that is editable via the normal page/post editing means, rather than just through manual editing of a text widget.

KB Advanced RSS Widget – WordPress comes with an RSS widget, but the styling/display options are practically non-existent. If you want to be able to style the display of your RSS widget to fit within your theme, you definitely want to try this plugin.

Lightbox 2 – I'm sure you've seen those fancy image popups where the rest of the page looks like you've turned the lights down while a big version of the image you clicked on is displayed in the foreground: that's Lightbox. There are a lot of other plugins and features that can use Lightbox, but you can also use it by itself.

Sociable – If you've ever wanted to add those little icons to a dozen or more different social media sites for users to submit your links, this is the plugin you need. It's highly configurable with many, many different social sites to choose from, and it includes links to email and print the content.

TinyMCE Advanced – I really don't know why this isn't part of the default install of WordPress. Maybe there are other options that people like so they leave it up to you to choose which plugin you want to use, but the default WYSIWYG editor is really insufficient for anything more than basic rich text editing. With this plugin, you get a lot of the missing functionality and a lot of customization to suit your needs.

Unfancy Quote – I really hate curly quotes. You know, the ones that MS Word gives you. WordPress has curly quotes by default so your quoted text “looks like” this "rather than like this". Maybe it's because I'm a programmer, but I pretty much never want curly quotes unless I'm writing a novel, in which case I will use Word. This plugin changes the default rendering of quotes so that they appear as you actually enter them.

Viper's Video Quicktags – Embedding videos into your posts can sometimes be tricky. Viper's Video Quicktags plugin helps make this process easier and it's customizable. This works especially well if you use YouTube a lot. You can even specify the default dimensions of the player, which really helps.

WP-DBManager – I've always been paranoid about losing the data in my blog. I ran into this plugin a year or so ago, which not only regularly backs up your WP install, but it also emails you the file. I've been using this on every WP site since.

WP Super Cache – Super Cache is a bit of a dual-edged sword because if you forget that you're running it, it can cause quite a headache. It caches your WP pages into static content so they can be served much more quickly. This is great if your site hits Digg or gets Slashdotted, but if you're trying to debug a theme tweak or some other change, it can be a huge pain if you forgot to turn it off. The other thing about this plugin is that if you're reading my blog, your site probably doesn't get enough hits for you to really need this. And yes, I know I don't need it either. ;)

Yoast Breadcrumbs – If you want to use breadcrumb navigation on your site, this is the best plugin I've found, and even this needed some behavior modification at the page-render level. I'll probably post up the details of those tweaks at a later date, but this is a really good place to start if you want breadcrumbs. [Edit: Here's the link to the post I mentioned that I would write.]

If you've got any must-have plugins that you'd like to recommend, I'd love to hear about them. Leave a comment with your thoughts, a description, and a link to the plugin if you want to suggest one. Happy WordPressing!


  • email
  • Print
  • Google Bookmarks
  • Twitter
  • Facebook
  • MySpace
  • Digg
  • LinkedIn
  • Slashdot

Mar

23

GoDaddy Shared Hosting Multiple-Domain And Subdomain Management

If you use GoDaddy's shared hosting plans that support multiple domains (the Deluxe or Unlimited plans) and you've tried to manage multiple domains and subdomains, then you probably are already familiar with the organizational frustrations that can occur.

In a standard web server environment, each domain and subdomain has it's own directory, usually under a hosting directory, like this:

~/
     myprimarydomain.com/
          www/
               index.html
               ...
          somesubdomain/
               index.html
               ...
     myotherdomain.net/
          www/
               index.html
               ...
          someothersubdomain/
               index.html
               ...

Unfortunately, with the Godaddy shared hosting plans, some domain must be the primary domain and it must live in the root. That is, you'll end up with a directory structure like this.

~/
     footer.php
     header.php
     index.php
     images/
          ...
     javascript/
          ...
     myotherdomain.net/
          index.php
          ...
     picturessubdomainforprimarydomain/
          index.php
          ...
     someotherdomain.org/
          index.php
          ...
     ...

As you can see, this gets pretty muddy when you have the code for a website for your primary domain mixed in with your other domains and subdomains. Unfortunately, there's no way to completely fix this issue with the inexpensive hosting plans. However, you do have a few options to organize your hosting directory.

Option 1 – The "Primary Domain Gets Screwed" Solution

You can setup a domain that you don't care about for the primary hosted domain. Then, just don't put anything in the root and start organizing your domains in folders with subdomains in those folders. With that method, you have to buy an extra domain that you aren't going to use.

Another way you can do this is with a root-level redirect. You can put a single redirect in the root to point the primary domain to its properly nested directory. The problem with this is that you are going to get a long junky URL (after redirect, http://www.mydomain.com/managed_domains/mydomain.com/www/index.php) for the primary domain unless you can get mod_rewrite to work with GoDaddy. I haven't tried this, but I suspect you won't be able to rewrite the URLs in a pretty manner as you aren't allowed access to the Apache httpd.conf file.

Option 2 – The "Try To Keep The www Subdomain Content For Your Primary Domain Well-Organized/Minimal And Manage All Your Other Domains And Subdomains Correctly" Solution

Okay, maybe that solution needs a better name. :)

This is the solution I'm currently using. My kennycarlile.com is my primary hosted domain, so I have to keep my www content in the root. I wanted to organize my other domains (and subdomains for kennycarlile.com), so I put my www.kennycarlile.com content in the root and then created a folder for other domains called "000_other_domains". I chose this name, with leading 0's because that will force it to always (well, in theory) put that directory first in an alphabetical listing of the parent directory.

Within ~/000_other_domains/, I then create a folder for each domain, independent of the subdomain. That is, I have ~/000_other_domains/kennycarlile.com/ as a parent folder for all my other subdomains. For this case where this is for the primary domain, the www directory exists at the root (~/), but all other domains exist in this directory:

~/
     000_other_domains/
          528digital.com/
               www/
          frofrolynx.com/
               www/
          kennycarlile.com/
               demo/
               wiki/
               [www/ does not exist here because this is the
                    primary domain and it must exist at ~/]
          kennycarlile.net/
               gallery/
               www/
          moonfar.com/
               www/
          nwdirtriders.com/
               forum/
               gallery/
               www/
          ...

While you still end up with your primary domain's www directory mixed in the root with the 000_other_domains/ directory, you have the rest of your domain and subdomain structure organized logically.

Option 3 – The "You're Actually Making Money From Your Site So You Can Afford Some Real Hosting" Solution

If you're making money off your site and it's not just a hobby, you can probably splurge for the $35+/month virtual dedicated hosting that allows you to have a lot more control over your Apache configuration. This isn't a really a solution since the issue is trying to fix the shared hosting problem, but I just wanted to point out this option.

Fixing A Poorly Planned Hosting Setup

I hope that helps someone out there. I would have liked to have seen this kind of write up prior to starting to manage my hosting. As it was, I had all of my domains and subdomains in folders at the root (~/) of my hosting directory. To clean this up, I had to move many of my installs. I was worried about breaking/corrupting my applications that GoDaddy had installed for me (WordPress, PHPbb, Twiki, etc.), so on the advice of one of their very helpful and articulate tech support reps, I followed these steps:

  1. Using GoDaddy's File Manager in their hosting tools, create the 000_other_domains/ directory.
  2. Now create a directory for each domain under 000_other_domains/, such as kennycarlile.com/, frofrolynx.com/, etc.
  3. Using the File Manager tool, COPY the improperly placed folder where your subdomain (that includes the implicit ones like www, except for your primary domain, which has to stay at ~/) and rename the copied folder as appropriate. You should now have a directory structure like ~/000_other_domains/frofrolynx.com/www/ where a copy of your frofroynx.com content resides.
  4. In domain management, modify the record for each domain and subdomain (do subdomains first so you can go back and mange the parent domain while you are waiting for the subdomains to take effect, which happens every 30 minutes), so that it points to the NEW location: ~/000_other_domains/frofrolynx.com/www/. Again, this will take ~30 minutes to take effect.
  5. Rename your OLD directory to something like xxx_[foldername] so that you know 100% that you aren't accidentally seeing the old install because the domain change hadn't yet taken effect. This also helps you identify which folders you need to delete later.
  6. Now test your install. For some applications or plugins for applications, you may have to edit config files to point to the new server path, such as changing /home/content/u/s/e/username/html/old_domain_directory/… to /home/content/u/s/e/username/html/000_other_domains/frofrolynx.com/www/…
  7. Once you've been able to correct all the absolute paths to point to the new one, test again.
  8. After a day or two, if you feel confident that everything is working as is, you can delete your xxx_[foldername].

Well, that about covers my experience with trying to fix a poorly-managed (by me) hosting account on GoDaddy's shared hosting. Hopefully that will safe someone else some pain and hassle by learning from my mistakes and experience. Good luck!


  • email
  • Print
  • Google Bookmarks
  • Twitter
  • Facebook
  • MySpace
  • Digg
  • LinkedIn
  • Slashdot