Next Image
Make the current image sticky.
Previous Image
randys.org - randys.org

Archive for July, 2004

Gmail

It seems that Gmail has sparked quite a bit of interest in the past several months. I’ll admit I was itching to get an account for quite some time. A whole gig of storage is unheard of these days (well, not so much anymore with the rest of the free webmail services offering similar services). I finally got my grubby little hands on an invite just this week.

I’ve been trying it out over the past couple of days. It’s really fast (of course, I don’t have but a handfull of emails in the system yet). I keep trying to sign up for a PHP mailing list (which are extremely high volume) but their system seems to be broken at the moment. We’ll see how this pans out…

• • •

Google Friendly URLs with PHP and Apache

Dynamic websites are essential for content heavy sites and chances are, you’re not going to create one static page for every single page/article/product item you have stored in a database. This means you’re going to need to pass parameters to your script to pull the right content from your database. Up until recently, most people didn’t give much thought to those nasty URLs with all those ampersands (&) and equal signs and how they affect spidering by search engines. While these URLs are perfectly valid, they tend not to get indexed by Google (and other search engines) unless you submit each URL for indexing (which can cost you money). And these days, if you’re not in Google, you’re not being found.

Enter PHP and Apache

<p><p>If you&#8217;re using <span class="caps">PHP</span> and Apache, you can still be dynamic and be spidered by all the popular search engines fairly easily. Of course, this depends on your hosting provider and how much control they let you have in terms of htaccess. <span style="font-style: italic;">.htaccess </span>files let you manipulate some Apache settings on a per host/per folder basis. Have a look at the <a href="http://httpd.apache.org/docs/">Apache manual</a> for a full listing of configuration settings for Apache web server.</p></p>


<p><p>Now for the goods. Here&#8217;s a basic rundown of how search engine friendly URLs can be used in a dynamic way. Let&#8217;s say you have a catalog of items, and your script takes 3 parameters: &#8216;section&#8217; , &#8216;action&#8217;, and &#8216;item.&#8217; Normally, when passing parameters to a script, your url will look something like this:</p></p>


<p><pre><code>/index.php?section=widgets&#38;action=view&amp;amp;item=327</code></pre></p>


<p><p>With the proper directives in an Apache .htaccess file and some simple <span class="caps">PHP</span> scripting, you can turn that <span class="caps">URL</span> into something like this:</p></p>


<p><pre><code>/catalog/section/widgets/action/view/item/327</code></pre></p>


<p><p>Looks like a bunch of folders, but it&#8217;s not. &#8216;catalog&#8217; is actually a file (a <span class="caps">PHP</span> file) without the extention, and with the help of a <span style="font-style: italic;">.htaccess</span> file,  Apache treats it like a <span class="caps">PHP</span> script.  Here&#8217;s what the <span style="font-style: italic;">.htaccess</span> file looks like:</p></p>

ForceType application/x-httpd-php

That’s it. Nothing too complicated. Now for the trickier part, grabbing those parameters from the URL with PHP.

<p><p>There&#8217;s a server variable that gets passed to the script calle &#8216;PATH_INFO&#8217; which contains the entire string after the catalog file (including that first slash). To grab it in a <span class="caps">PHP</span> script, you&#8217;d use the <a href="http://us2.php.net/manual/en/reserved.variables.php#reserved.variables.server">$_SERVER</a> global variable (a la $_SERVER[&#8216;PATH_INFO&#8217;]). The idea is to <a href="http://us2.php.net/manual/en/function.explode.php">explode</a> the string into an array and loop through them to get the parameters. Here&#8217;s a small function to do so:</p></p>


<p><pre><code>&lt; ?php

function getArgs() { $params = explode(“/”, $_SERVER['PATH_INFO']); } ?>

<p><pre><code>for($i = 1; $i &lt; sizeof($params); $i = $i + 2)

{ $args[$params[$i]] = $params[$i+1]; } return $args;

<p><p>When used on the above example, this function will return an array like so:</p></p>


<p><pre><code>Array (
 [section] =&gt; widgets
 [action] =&gt; view
 [item] =&gt; 327

)

<p><p>Implimenting this into a current site shouldn&#8217;t be too hard. The &#8216;catalog&#8217; script would simply be a wraper script where you can pass the required values into existing code.</p></p>


<p><p>If you find that your web host doesn&#8217;t allow use of .htaccess files, or they don&#8217;t allow the &lt;Files&gt; directive to be used, you can do one of two things (and I highly recommend the first).</p></p>


<p><p>1) Change hosts! I use <a href="http://www.dreamhost.com/rewards.cgi?sesser">Dreamhost</a> and they are extremely flexible, have an awsome support team and have a <a href="http://www.dreamhost.com/rewards.cgi?sesser/shared/comparison.html">very good deal for $9.95/mo</a>.</p></p>


<p><p>2) Just use a normal <span class="caps">PHP</span> script (i.e. catalog.php) and use the same function. While this method works, I&#8217;ve read that some search engines see this as a hack/cheat and might not spider the pages anyway. However, if you are a reputable business, you can usually contact them and get your pages indexed.</p></p>

Other Web Servers

<p>If you&#8217;re running <span class="caps">IIS</span> (god forbid), there is hope for you. There is at least one product (ISAPI) available that mimics the Apache mod_rewrite module. This <span class="caps">ISAPI</span> can help do the same thing (although it won&#8217;t be quite as easy). But the drawbacks are that a) the <span class="caps">ISAPI</span> isn&#8217;t free and b) if you&#8217;re in a shared environment, you can&#8217;t use it. There are other ways to manipulate your <span class="caps">IIS</span> settings to use search engine friendly URLs, but they all have their downsides. Bottom line: stop using <span class="caps">IIS</span>.</p>


<p>As for other servers, I can&#8217;t really say. Chances are there are some tweaks that can be made to the configuration and/or scripts. If you know of any, please drop me a line and I&#8217;ll try to get it posted.</p>
• • •

Google Friendly URLs with PHP and Apache

Dynamic websites are essential for content heavy sites and chances are, you’re not going to create one static page for every single page/article/product item you have stored in a database. This means you’re going to need to pass parameters to your script to pull the right content from your database. Up until recently, most people didn’t give much thought to those nasty URLs with all those ampersands (&) and equal signs and how they affect spidering by search engines. While these URLs are perfectly valid, they tend not to get indexed by Google (and other search engines) unless you submit each URL for indexing (which can cost you money). And these days, if you’re not in Google, you’re not being found.

Enter PHP and Apache

If you’re using PHP and Apache, you can still be dynamic and be spidered by all the popular search engines fairly easily. Of course, this depends on your hosting provider and how much control they let you have in terms of htaccess. .htaccess files let you manipulate some Apache settings on a per host/per folder basis. Have a look at the Apache manual for a full listing of configuration settings for Apache web server.

Now for the goods. Here’s a basic rundown of how search engine friendly URLs can be used in a dynamic way. Let’s say you have a catalog of items, and your script takes 3 parameters: ‘section’ , ‘action’, and ‘item.’ Normally, when passing parameters to a script, your url will look something like this:

/index.php?section=widgets&action=view&item=327

With the proper directives in an Apache .htaccess file and some simple PHP scripting, you can turn that URL into something like this:

/catalog/section/widgets/action/view/item/327

Looks like a bunch of folders, but it’s not. ‘catalog’ is actually a file (a PHP file) without the extention, and with the help of a .htaccess file, Apache treats it like a PHP script. Here’s what the .htaccess file looks like:

<br />&lt;Files catalog&gt;
<br />     ForceType application/x-httpd-php
<br />&lt;/Files&gt;
<br />


That’s it. Nothing too complicated. Now for the trickier part, grabbing those parameters from the URL with PHP.

There’s a server variable that gets passed to the script calle ‘PATH_INFO’ which contains the entire string after the catalog file (including that first slash). To grab it in a PHP script, you’d use the $_SERVER global variable (a la $_SERVER[‘PATH_INFO’]). The idea is to explode the string into an array and loop through them to get the parameters. Here’s a small function to do so:

<br />&lt;?php
<br />function getArgs()
<br />{
<br />    $params = explode("/", $_SERVER['PATH_INFO']);
<br />
<br />    for($i = 1; $i < sizeof($params); $i = $i + 2)
<br />    {
<br />        $args[$params[$i]] = $params[$i+1];
<br />    }
<br />    return $args;
<br />}
<br /> ?&gt;
<br />


When used on the above example, this function will return an array like so:

<br /> Array (
<br />     [section] => widgets
<br />     [action] => view
<br />     [item] => 327
<br /> )
<br /> 


Implimenting this into a current site shouldn’t be too hard. The ‘catalog’ script would simply be a wraper script where you can pass the required values into existing code.

If you find that your web host doesn’t allow use of .htaccess files, or they don’t allow the <Files> directive to be used, you can do one of two things (and I highly recommend the first).

1) Change hosts! I use Dreamhost and they are extremely flexible, have an awsome support team and have a very good deal for $9.95/mo.

2) Just use a normal PHP script (i.e. catalog.php) and use the same function. While this method works, I’ve read that some search engines see this as a hack/cheat and might not spider the pages anyway. However, if you are a reputable business, you can usually contact them and get your pages indexed.

Other Web Servers

If you’re running IIS (god forbid), there is hope for you. There is at least one product (ISAPI) available that mimics the Apache mod_rewrite module. This ISAPI can help do the same thing (although it won’t be quite as easy). But the drawbacks are that a) the ISAPI isn’t free and b) if you’re in a shared environment, you can’t use it. There are other ways to manipulate your IIS settings to use search engine friendly URLs, but they all have their downsides. Bottom line: stop using IIS.

As for other servers, I can’t really say. Chances are there are some tweaks that can be made to the configuration and/or scripts. If you know of any, please drop me a line and I’ll try to get it posted.

• • •

Modest Mouse @ The Avalon

So, last Sunday we drove up to Hollywood to see Modest Mouse at the Avalon. They put on a good show. This is the second time we’ve seen them live (the first time being the KROQ Weenie Roast). There were two other bands that opened up for them, one of them being The Walkmen. I wasn’t too impressed so we just kind of hung out in the lobby and did some people watching. While waiting for Modest Mouse to come on, we saw Danny Masterson (a.k.a Steven Hyde from That 70s Show), Giovanni Ribisi (a.k.a Daniel from The Other Sister), Adam Goldberg (a.k.a The Hebrew Hammer), Christina Ricci (a.k.a Wednesday from The Addams Family), and Kevin Weisman (a.k.a Marshall J. Flinkman from Alias). Apparently, Chrstina Ricci is dating The Hebrew Hammer (which is a little odd, but whatever, to each their own…sorry Brian). After the show, we kind of hung out in front of the venu and we saw a few more people from The O.C.

I digress.

I really like the new album from Modest Mouse. It’s not my favorite, but it’s still not crap. I worry that now that they are getting bigger (selling out?) that future albums will turn to crap. I’ve been listening to them since probably early ‘01 while in school at Chico State. They used to play in Chico quite often (at least 4 times in 3 years), but I never went to see them… should have.

• • •

More Work Related Ranting

Well, it’s been settled. I’ve chosen to change departments and leave the IT side of things. I’m moving into the marketing department instead. I suppose this is closer to what I’d really like doing (as far as design goes anyway). I like coding and whatnot, but the state of affairs in my particular IT department is unstable at best. We’ve gone through 2 managers in the past year (one of wich only lasted about 2 weeks). The current manager of IT lives about 350 miles from here so he’s not around a lot…not to mention he’s having a baby in the next day or two (well, he’s not, but his wife is).

So, yeah, I’m movin’ up in the world…physically anyway. Going from the first floor to the second.

• • •

All content Copyright © 1999 — 2010 Randy Sesser | Happily Hosted by WebFaction
Entries (RSS) | Comments (RSS)