RSS Feed

March, 2010

  1. What do you want to learn more about?

    March 30, 2010 by Austin Hallock

    My last post didn’t seem to be that big of a hit — maybe that’s because you all could care less about mod_rewrite.

    What would you like me to write an informative post on? If you have any ideas for some sort of script like the overlay box and banner creator, let me know and I can do that too.

    Post your suggestions in the comments section.

    Thanks!

    P.S. just so this post has some sort of content, here’s a picture of my newly acquired living room furniture….


  2. Fun with mod_rewrite

    March 25, 2010 by Austin Hallock

    Ever wanted your page that has an ugly URL like:
    /index.php?page=whatever&long=2&parameter=3
    to look like /whatever/2/3?

    It’s actually pretty easy and done through something called mod_rewrite.

    Mod_rewrite can get pretty complicated and get into a ton of regular expressions, but for most uses, just copy and paste what I have and make any necessary changes.

    Mod_rewrite goes in the .htaccess file on your server (in the main public html directory). If your server has it, edit the file, if not create one — it’s just .htaccess, nothing before the period.

    Here’s the base code you’ll want to start with (but will need some modification) All of this is color coded so hopefully that helps:

    RewriteEngine on
    RewriteRule ^([^/]+)/?$ index.php?page=$1&%{QUERY_STRING} [L]
    

    For example, if you want /index.php?action=anything to look like /anything what you’ll need is:

    RewriteEngine on
    RewriteRule ^([^/]+)/?$ index.php?action=$1&%{QUERY_STRING} [L]
    

    The above code will make /login essentially cloak /index.php?action=login, /register will load/cloak /index.php?action=register etc…

    If you only want /login to go to /index.php?action=login and not have it happen for /anything you would want something like this (no wildcard):

    RewriteEngine on
    RewriteRule ^login/?$ index.php?action=login&%{QUERY_STRING} [L]
    

    You can also do this for multiple parameters, so to go back to that first example of making /index.php?page=whatever&num1=7&num2=6 look like /whatever/7/6 you would want to use:

    RewriteEngine on
    RewriteRule ^([^/]+)/([0-9]+)/([0-9]+)/?$ index.php?page=$1&num1=$2&num2=$3&%{QUERY_STRING} [L]
    
    • Here’s a bit of an explanation of what that all means…Starting at the 2nd line, the rule is it’s searching the URL (when someone visits a page on your site) for ([^/]+) which is any combination of characters/numbers *except* a forward slash. The + means it must match at least one character.
    • ([0-9]+) Looks for any number
    • /?$
      • The / looks for a forward slash
      • The ? means that forward slash is optional (if it’s there it works if it’s not it still works)
      • $ means it’s at the end of the URL. So it matches for http://anything.com/anything/ and http://anything.com/anything, but not http://anything.com/anything/somethingelse.
    • After the space is the URL it will load once there is a match
      • $1 is a wildcard for the first contents of parenthesis, so it refers back to (^/) and what it stood for. In this case it stood for “whatever
      • $2 is a wildcard for the 2nd set of parenthesis, $3 for the third and so on.
      • %{QUERY_STRING} just allows extra stuff to be put on the end so if I did /whatever/7/6/?test=test it would pass the test parameter as well.

    Want to get into some more advanced mod_rewrite? Here’s a nice little cheat sheet. If you have questions, post them in the comments.


  3. Overlay a Lightbox on a Page

    March 20, 2010 by Austin Hallock

    Here’s a cool script I just made that allows you to overlay a lightbox with whatever you want in it on any page (Google, this site, etc)

    Drag the link below into your bookmarks

    and click it on any site you want to cloak / put a “light box” (an overlaying box) on. When you click the bookmarklet it’ll ask what you want to show in the box, just type that, hit save and you’re done.

    Overlay

    YO

    Here’s an example: Google
    Tweet this

    Hope you like it and let me know how I can improve it!


  4. Quick and Easy Banner Creator v3

    March 18, 2010 by Austin Hallock

    So, since everyone seems to like the banner creator, I’ve done some more work on it.

    The biggest new feature is the addition of multiple background images.

    Here are a couple examples:

    You can check it out here: http://trkr.me/5f

    As always, let me know what you think!


  5. Quick and Easy Banner Creator v2

    March 14, 2010 by Austin Hallock

    I’ve made some updates to the banner creator I posted about yesterday. Some changes include:

    • You can now pick custom background colors
    • Same goes for font color
    • Better alignment
    • Text is now wrapped, so you can enter longer text and it will force it to a new line.

    You can access it here: http://trkr.me/5f