Tag Archives: Web

Wildcard DNS and Sub Domains

What follows is what I consider to be best practice for my personal sites and a guide for those who wish to do the same. Months ago I dropped the www. prefix from my domain in part because I think it’s redundant and also because I wanted to experiment with how Google treated valid HTTP redirect codes. The experiment has been a great success. Google seems to fully respect 301 Permanent Redirects and the change has taken my previously split PageRank has been combined and now I am at 7. There are other factors that have contributed to this, of course, and people still continue to link to my site and posts with a www. (or worse) in front of it, but overall it just feels so much cleaner to have one URI for one resource, all the time. I’m sure that’s the wrong way to say that, but the feeling is there nonetheless.

Now for the meat. What’s a good way to do this? Let’s look at our goals:

  • No links should break.
  • Visitors should be redirected using a permanent redirect, HTTP code 301, meaning that the address bar should update and intelligent user agents may change a stored URI
  • It should be transparent to the user.
  • It should also work for mistyped “sub domains” such as ww. or wwww. (I still get hits from Carrie’s bad link)

So we need a little magic in DNS and in our web server. In my case these are Bind and Apache. I am writing about this because at some point the code I put in to catch any subdomain stopped working and while I reimplemented it I decided to write about what I was doing. This method also works with virtual hosts on shared IPs where my previous method did not.

In Bind you need to set up a wildcard entry to catch anything that a misguided user or bad typist might enter in front of your domain name. Just like when searching or using regular expressions you use an asterisk (or splat) to match any number of any characters the same thing applies in Bind. So at the end of my zone DB file (/var/named/photomatt.net.db) I added the following line:

*.photomatt.net. 14400 IN A 64.246.62.114

Note the period after my domain. The IP is my shared IP address. That’s all you need, now restart bind. (For me /etc/init.d/named restart.)

Now you need to set up Apache to respond to requests on any hostname under photomatt.net. Before I just used the convinence of having a dedicated IP for this site and having the redirect VirtualHost entry occur first in my httpd.conf file. That works, but I have a better solution now. So we want to tell Apache to respond to any request on any subdomain (that does not already have an existing subdomain entry) and redirect it to photomatt.net. Here’s what I have:

<VirtualHost 64.246.62.114>
DocumentRoot /home/photomat/public_html
BytesLog domlogs/photomatt.net-bytes_log
ServerAlias *.photomatt.net
ServerName www.photomatt.net
CustomLog domlogs/photomatt.net combined
RedirectMatch 301 (.*) http://photomatt.net$1
</VirtualHost>

The two magic lines are the ServerAlias directive which is self explanitory and the RedirectMatch line which redirects all requests to photomatt.net in a permanent manner.

There is a catch though. The redirecting VirtualHost entry must come after any valid subdomain VirtualHost entries you may have, for example I have one for cvs.photomatt.net and I had to move that entry up in the httpd.conf because Apache just moves down that file and uses the first one it comes to that matches, so the wildcard should be last.

That is it, I’m open to comments and suggestions for improvement.

Beginning On PhotoStack

It’s an entirely pleasant, rainy day, so I thought it would be a wonderful time to get going with Noel’s PhotoStack. I grabbed the latest version available and uploaded it to the server.

Trying to be as true as to I would actually use a program like this, I didn’t read any of the documentation. Plus there’s a readme file, but it has no extension so opening it means no less than three or four dialogs in Windows XP. A .txt extension wouldn’t hurt anybody. It gave me a message that the storage directory wasn’t set up properly, which told me that I probably need to edit a configuration file of some sort. So I fire up SSH. A ls -lah (which I have aliased as ll) shows a config.php, which I guess is what I’m looking for.

I fire up the one true editor. There seems to be a little more at the top than necessary and it doesn’t say much, but that’s a personal peeve. The varible names seem logical (some camelCase going on) but the descriptions above each is not always helpful. Mostly it’s just $photosName. I’ve never used the program before, and the description “The name of your Photos section.” makes sense to me as an English sentence but I don’t quite grok its significance.

Next up is the path information, which could possibly be streamlined. First we have $dirRoot where PhotoStack seems to want the absolute path to the script. It recommends “$_SERVER[‘DOCUMENT_ROOT’].’/photos’ may work for you.” but even though that makes perfect sense I’ve dealt a lot with this in WordPress. More people have messed up DOCUMENT_ROOTs than you could ever imagine, there are a few other solutions that may be better. One I’ve had good success with is dirname(__FILE__). which works like a charm for finding the absolute path of the current directory. realpath() may also be helpful, but we use the first trick in WordPress. The next variable is the URI of where PhotoStack is located, with the instruction “no trailing slash.” This is another pet peeve, but an instruction like this should be avoided at all costs. No trailing slash there, should I have a trailing slash on $dirRoot? It didn’t say anything. It causes confusion. It’s programatically trivial to detect and remove a trailing slash on this variable, so why even bother the user? Don’t make me think.

There are a lot more configuration options, a lot. It suggests replacing “no” with “yes” or vice versa to change the value. While this is probably more intuitive than boolean values of true or false, I think spelling out “yes” or “no” several times is a little patronizing. I know, impossible to please.

Okay so I’m done with the configuration file, I reload the URI. Still doesn’t work! I’m guessing it’s time to go to the readme, probably the storage directory needs to have permissions set or something. There is no wrapping in the file, which means each paragraph stretches really far and to read it I’ll have to scroll horizontally in my editor. Wrapping at 72 characters would probably not be a bad idea. Fortunately I know a shortcut (ctrl + j) to fix this but that’s just luck. I find out the software is licensed under the Creative Commons Attribution-NoDerivs-NonCommercial license, which I suppose means I can never use this for a paying client and if I want to improve on the code and release the changes without explicit permission from Noel. If Noel fell off a cliff I suppose the code would be locked under the license and development would halt? I don’t know exactly, but that’s what goes through my mind. Generally I’m much more comfortable with more liberal licenses, be it MIT or GPL or Artistic or anything Free. Next it says:

Templates in PhotoStack are not licensed as part of PhotoStack. Therefore, they are not subject to the licensing terms of PhotoStack. I’m placing this decision in the realm of Mr. Allen… If anyone can lend some clarification that would be great.

That doesn’t inspire the greatest confidence, but I’m planning to modify the templates anyway so maybe I should worry. Finally at the end it tells me to chmod 777 the storage directory. Ah, what I needed to know. I have heard some peopl ecomplain about the liberal chmod requirement before, but it’s really only necessary because of the way most web servers are set up to execute PHP, which I suppose could change in the future. It’s no problem to me. I secure things at a much lower level.

I’m already at the command line so it’s a simple matter to modify the directory. No errors but the pictures don’t load. Whoops, I missed setting $webDir variable, probably because I was planning to talk about it but went off on a tangent. The default value of this is “http://yoursite.com/photos”, and this is splitting hairs but there are several domains expressly for this purpose and an RFC to back them up. It’s a good practice because since yoursite.com isn’t reserved, it could theorectically be taken by some unsavory character that used its ubiquity in examples in some malicious fashion. You never know.

It loads! However I click on the sample album and there’s something funky going on with the layout. Perhaps it has something to do with the size I set my thumbnails at (150×150, though I would like to just be able to say something like 150 px on its longest side and allow it to keep its proportion, or just 150 px wide all the time. I’m not crazy about every thumbnail being square). What ever it is it will have to wait until tomorrow because it is past my bedtime. Hopefully tomorrow I can start loading this thing up with photos.

“Matthew! How could you possibly be so nitpicky with this poor guy’s project? How would you like that if someone did that to your project?” Actually, I would be thankful and flattered. If I didn’t like Noel and think PhotoStack could be great I wouldn’t be spending time documenting my thoughts on it. Constructive feedback is golden to an open-minded developer.

Mr Mailman is Back

A late night meant I woke up to the sound of the delivery man knocking on the door. Three brisk taps signalled that my package from Amazon had come, containing most notably Jeffrey Zeldman’s new little orange book, Designing with Web Standards. The cover is freaking me out up close (is that a moustache?) and Amazon bent it a little, but it looks fantastic! So much to read, so little time.

Upgrade Day

Just finished upgrading the server to address a mod_ssl vulnerability and get PHP 4.3.2. It went swimmingly, which is always nice.

In the process of upgrading about half a dozen sites to WordPress .71 to test it out before the code is released. It’s a good process because the sites need updating (security problem again) and it’s a good way to find any bugs that may have made it through so far.

I’ve always remarked that people tend to write about bad things more than they write about good things. Journals, blogs, diaries, all tend to be one-sided, at least in my experience. As is such though yesterday started quite badly, after I emerged from my migraine-medicine–induced haze I had a pleasant evening with my family.

Today has been great too; been hanging out with Mike and Christine at Kaveh Kanes (where the chai is tasty and the music is grooving) getting Christine set up in email utopia, where spam is like the distant buzzing of a fly you think you heard but you’re sure it’s really just in your head. Back to work! There looks to be some frisbee in the plans this evening…

Update: Mike has a meta moment.

Blogging by Degrees

There’s a new tool called Downhill that attempts to find the connections between two weblogs. It’s a neat idea however nothing I tried worked. It also seemed to force an old URL (the www. one) for this site, so I don’t know what that means. You might have better luck though, so check it out. [via CamWorld]

WordPress Picking Up Pace

Today has certainly been an exciting day so far. First of all, Donncha has joined the WordPress team, bringing the number of developers officially to three. There have been several other inquiries and I think it’s exciting and the development will move along pretty fast.

I’m trying my hardest at least. I got a couple of things out of the way this morning: first the displays of comments, pingbacks, and trackbacks are all combined and present chronologically interspersed amoung each other. They really are all comments, and now they display as such. This also eliminates some link clutter, Josh will be especially happy since according to him “The trackback link is the ugliest thing I have ever seen in my life.”

Next I went through most all of the code and converted all the mysql_* functions to use the ezSQL class, which I found through Simon (who is running an excellent CSS series right now, by the way). ezSQL has become a huge timesaver and cleaned up a lot of code in different projects I do, including Mullenweg.com where it sped up things quite a bit as well.

As that was happening I refactored all of the template code, taking out some things that weren’t necessary anymore and just in general cleaning things up. After I finished all this I was disappointed to see that there wasn’t a noticable speedup, but that’s actually in line with the profiling I did a couple of weeks ago that showed the bulk of the processing happening in some of the character conversion code. If someone else can focus on features for a few days I’d really love to dig into that code and see if we can’t get a substantial speedup from optimizing it. Of course a lot of this will be less significant once we get Smarty caching in place, but having a very streamlined and efficient application before caching never hurt anybody.

For now though it’s time for a break, and lunch with Kathy and Elaine is just what I’ve been looking forward to.

Brand New PHP

The latest version of PHP looks fabalous, and contains a number of necessary fixes on top of the normal feature enhancements. Besides Python, I can’t think of another language that progresses as nicely as PHP. It looks like Apache 2 support is finally golden as well. This should be an interesting upgrade.

WordPress Now Available

Extra, extra, read all about it.

I am very happy to announce that the first release of WordPress is now available for download. A full change log is available, but here is a brief overview of the new features.

  • Texturize — So good it’ll make your quotes curl.
  • WordPress Links — A link manager with everything you’d expect, from Weblogs.com support to a handy bookmarklet. Manage as many blogrolls as you like, and have complete control over their display.
  • XHTML 1.1 — WordPress is complaint with XHTML standards up to 1.1, though by default it sends a 1.0 document type to avoid compatibility issues.
  • Highly Intelligent Line Breaks — Occasionally called “nl2br on steroids,” this brand new function adds line breaks except where there is already a block level tag or another line break.
  • New Administration Interface — We’ve made it as simple as possible, and no more. Everything has been restructured from the ground up in a fully compliant XHTML/CSS interface.
  • Manual Excerpts — This allows you to handcraft summaries of your posts to appear in your RSS feed and other places.
  • New Default Templates — Again we’ve streamlined theses with the latest in simple, easy-to-understand standard XHTML and CSS. And not a CSS hack in sight.
  • Plus numerous behind the scenes code cleanups, making this release faster and more stable than ever.

WordPress is available completely free of charge under the GPL license. Enjoy!

Go get it, and then go tell everybody about it. Many thanks! And now, it’s time for a party.

Whoa. WordPress.

Well, it looks like WordPress is going to become the official branch of b2, once we put out a release of course. Which should be soon, very soon. Time to start burning the midday oil. (I switched my sleeping hours.)

In other news i’m looking forward to seeing Michel’s new site, which he has some pretty cool thing planned for. He’s also doing more photography now, so maybe some cool b2 photolog features will come out of it. 🙂

Horde of Projects and Matrix

The Horde Project really has a lot of applications under its reign. In my opinion it’s by far the best web email client out there, but Kronolith, Jonah, and Gollem look really good. There should be a directory of high quality free PHP scripts. I’ve started using the Task application to track things I’m doing and should be doing, though the interface is a litle clunky. Something small and simple might be more in order.

Speaking of websites that should exist, Josh picked up This is the Matrix.net yesterday. Hopefully something cool will come out of it. 🙂

Oh No

It looks like Kymberlie and Christine have both been hacked, I only hope that the crackers didn’t do anything bad to their files and that it was a simple vulnerability and not one in Movable Type or something. Calling now… These guys (girls?) are so cool they did the hack announcement in FrontPage. Now that’s l33t.

A Better Image Rotator

The Hiveware Image Rotator, shared by Mr Zeldman, does one thing and does it fairly well: it shows a random image on each reload. However, the approach the script takes is slightly flawed, and could be improved as detailed below.

My first issue with the script is that it is really only set up to handle two types of files, GIF and JPEG, and then only with the file extensions of .gif or .jpg, so something like .jpeg (fairly common) would not be included. Not to mention the noble PNG is left out entirely. Fixing this, however, leads us to a more fundamental problem: the images are served through the script. This means that the script has to handle the content-type header, something that is messy to do. A better method, I propose, is for the script to merely serve a temporary redirect header, which sends the browser with a minimum of overhead to the actual location of the file, which has a number of tangential benefits including that it allows the image itself to be cached properly, either by a caching server or the browser itself, and it delegates content negotiation and such to the web server, which is most likely infinitely better at it.

So now what we have a script which reads files in a directory, grabs the ones with a user defined set of file extensions, and sends a simple Location header to whichever file is randomly chosen. The complication now that the location of the image is now important in terms of the web server document root. One bonus of Dan Benjamin’s method is you can use images outside of the web root, though I don’t know why anyone would want to do this. The script could ask for two variables to be defined, the absolute path to the images and the path to the images through the web server, but I would like for this to be as ridiculously easy to setup as possible. Another option would be to subtract the $DOCUMENT_ROOT variable from the absolute path given and use that, but that would require people to know the absolute path of the directory they’re using, and like I said I’d like this to be easy as humanly possible. The best solution is to use a relative path; if the users enters nothing it’s assumed that the images are in the same directory as the script but if they aren’t the path can be entered in a relative manner, like “images/random” or “../rand-img”. Easy peasy.

Finally, instead of the plain rand() we’ll use mt_rand, which is about four times faster and slightly more random. What do you get? The Photo Matt Random Image Script. I’ve tested it thoroughly, but if you have any problems don’t hesitate to let me know. It’s just standard HTTP though so I don’t foresee any trouble. Something neat about this is that with the code we just wrote, you can also serve random anything—from zip files to MP3s—just by changing the extension line. Enjoy! Here’s an example of it in action, you should recognize some of the images as the delightful graphics Jeffrey has been putting up, the rest are snips of photographs I haven’t uploaded yet.

A Random Image

Keeping the Faith

If you’re like me, you’ve been very concerned about the direction XHTML 2 has been heading. Very recently I’ve thought to myself that I won’t develop a commercial XHTML 2 site this decade. (Look how long it took them to get simple stuff right!) Only time will tell, but Tantek’s XHTML Considered Hopeful brings back that warm fuzzy feeling that promising new technologies give. Yes, it was going in a bad direction. Yes, it’s coming back.

I’ve lurked on www-html for several months now, maybe it’s time (and I finally have the time) to start seriously reading working draft and lend my voice to the process. That’s assuming of course I have anything cogent to say. I think the lesson to be learned here is if you’re concerned with where the spec is heading, let people know. As Tek says, they’re listening.

(My personal favorite new element so far? Gotta be <l>. Lots of possibilities there.)

Who Ya Going to Call?

From a trusted correspondent, talking with a contact who works at the Netscape part of AOL/Time Warner. “He said they had decided that weblogs are the next killer app, and that most of the work at the Mountain View office was going into building a weblog component for AOL. He also mentioned that about 400 people are working on that software. This is in constrast to about 20 who are working on Mozilla.” […] If there’s a problem doing this, please contact me, in confidence, if necessary.

Source. Three comments:

  1. I know Dave isn’t crazy about CSS and all that jazz, but could he at least use paragraph tags? Nothing by line breaks is so… never. Paragraphs have been around forever, no reason not to use them.
  2. 400 people working on it, assuming that even only 10% are actual developers (is this high?) I find it hard to believe that those 40 people will come upon a technical problem so insurmountable that only help from Dave, in confidence, if necessary, will help them.
  3. It also follows that if Microsoft and AOL/Netscape’s respective blogging tools or platforms don’t interoperate, I don’t think it will be because either lacks the technical skill to do so.

This is all pure speculation on my part, and I’m not afraid to admit it. I’m trying to think what kind of effect this could have on the blog world. There are already services out there such as Diaryland, Blogspot, Free Opendiary, Livejournal, Deadjournal, and Easyjournal that make the technical and financial barriers to something akin to blogging nonexistent. I know several people from my old school that might be hard pressed to send an email attachment but used one of the above tools with a degree of proficiency. What’s more these services, particularly OpenDiary and LiveJournal, tend to be very closed communities and don’t mingle much with blogs outside their service. So I think these new services in and of themselves will not be a big deal, however if they hook people on the concept and get them running for more advanced tools, then it could be significant. We’ll see.

Yum

Today has been a wonderful day feeling with code goodness. I don’t know why, but I really, really, really like playing around with XHTML. I find I enjoy programming in other languages (mostly PHP, but Python and Perl more now than before) most when it deals directly with XHTML. Anyway, I’m working on some really fun stuff and by this afternoon this site should be even more on the bleeding edge than it was before. Stay tuned.

Another Brand Spanking New Blog

It’s not Sunday anymore, but if you’ve still got nothing to do you should know that idle hands are the devil’s workshop, so by visiting idly.org, the new home of Adam, you’ll be doing a good thing. It seems that splitting blogs into public and personal is all the rage these days; I know Josh has one coming soon and I’ve been considering spinning something off PhotoMatt for a while. Oh just a side note, both of Adam’s domains are now with Spyder Hosting and rumor has it he’s enjoying it.