Categories: "Full Stack Dev & Design"

How to redirect to (or reverse)

Most sites can be reached by two different URLs. For example and .

This is good for the users who can choose whether or not to type in the "www." part. However, it is not good for search engines which will tend to see a lot of duplicate contents.

If you are on an Apache webserver, you can use mod_rewrite in order to redirect all traffic that goes to the www.domain to the "non www" domain. (If you want it the other way round, see below)

Try adding this to a file named ".htaccess" at the root of your site (create that file if it doesn't exist):


RewriteEngine on
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{HTTP_HOST}   !^your-domain\.com [NC]
RewriteRule ^/(.*)         http://your-domain\.com/$1 [L,R=301]

Note: More advanced users will prefer to add this to the httpd.conf / apache2.conf instead in order to gain a little efficiency and also to not interfere with tests on development/staging servers.


RewriteEngine on activates mod_rewrite.

The first RewriteCond makes sure we have a non(!) empty(^$) hostname to work with.

The second RewriteCond detects that the host name is not(!) the one we want (e-g: it has an extra www. part in it).

The RewriteRule sends out a permanent(301) redirection to the right domain name followed by the currently requested path/page ($1).

Handling multiple domains at once

Below is more elegant (yet complex to read) solution that can handle multiple domains at once (if you have "ServerAlias"es) and that doesn't require to type-in your domain (just copy/paste):


RewriteEngine on
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{HTTP_HOST}   ^www\.(.+)$ [NC]
RewriteRule ^/(.*)         http://%1/$1 [L,R=301]

The trick here is to use %1 which matches the canonical part of the domain name in the second RewriteCond (.+) .

Reverse redirection

By popular demand, here is how to redirect from to


RewriteEngine on
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{HTTP_HOST}   !^www\. [NC]
RewriteRule ^/(.*)         http://www.%{HTTP_HOST}/$1 [L,R=301]

Sitemaps priority is confusing

When looking at the sitemaps protocol which is now endorsed by Google, Yahoo and MSN, I can't help but crying about how obscure the documentation is, especially for the <priority> element.

Please note that the priority you assign to a page is not likely to influence the position of your URLs in a search engine's result pages.

Okay, so what's the point?

Granted that setting all priorities to 1.0 will not make the urls rank higher than urls from other sites. But we're talking about position of URLs here, not sites.

Sometimes, the same site appears multiple times in search results, with different pages/urls. In that case, if priority doesn't influence which URL comes first, compared to which other comes second, then what's the use?

For example, on a blog, the same info can be found on a post's permanent url, on the homepage, on the category page, on the archives pages, the RSS feed, etc.

Sometimes the search will return several of these locations. If the priority can't be used to tell that the permanent url would be the best choice to put first, then... I don't get it! |-|

Does it mean that priorities are only used to determine what gets crawled first? If it does, then it means that maybe the 100 top priorities will be indexed and the others won't! So the top 100 may appear in search results and the other may not!

Present vs. not present! That's what they call "not influencing the position'?

Again, if it doesn't do that, then what does it do?

All I can think of at that point is the priority being an alternative to <changefreq> : a site gets a certain number of reindexes a day, and high priorities pages will be refreshed more often that low priority pages.

That would comply with the definition of that <priority> does NOT do...

But then... it doesn't make sense with what it is *supposed* to do:

it only lets the search engines know which pages you deem most important for the crawlers.

Or by "most important", are we supposed to understand "most frequently updated"?

I really wonder who it helps to have that spec being so obscure... :>>

Apollo: the Flash Virtual Machine is getting better

Apollo: the Flash Virtual Machine is getting better

It was bound to happen. Macromedia's (well, Adobe's) Flash player finally evolved into a very complete Virtual Machine. They call it Apollo.

It basically solves the same problem Java has tried to solve for years: write once, run anywhere.

Though it's certainly less mature than Java today, I see several factors that could let Apollo succeed where Java has failed. Among these:

  • It leverages existing developers skills (HTML, Javascript, Flash...) which makes it look much more accessible than Java which only leveraged C++ skills.
  • It's gonna look nice out of the box. Java still looks relatively ugly...
  • With today's computers it's probably going to feel less painful and slow than Java back in 1996...

On the other hand, Sun has recently released Java as Open Source and that's certainly not a coincidence. I'm not sure what Adobe's pricing/distribution plans are with Apollo, but it certainly ain't gonna be as free as open source! :roll:

PNG not suited for webdesign!

I've been banging my head on my Mac & PC monitors with this! :'(

I had gone a long way already with color matching my Mac & PC displays, but this is far worse!

Suppose you have a logo on a plain color background that has a specific color code, let's say #A1B2C3.

  • If you save the logo as a GIF, you can just put it on a css background of #A1B2C3 and the background colors will match.
  • If you save the logo as a JPEG, it's a tiny little bit more complex but it still can be done. Just make sure that:

    1. You save the JPEG withOUT incorporating an ICC color profile
    2. You do not compress the JPEG so strong that it cannot encode a proper background color
  • If you save the logo as PNG-8... good luck! First there is no option (in Photoshop CS2 at least) to choose whether or not to include a color profile. But worse: it will include the gamma of you current display. So if you save the image on a Mac then try to display it in a PC browser, the displayed background of the image will no longer be #A1B2C3! IE7 and FireFox2 both try to compensate for the gamma being different on PC and Mac.

    If you now try to match the displayed color on your PC and put that into your CSS, then it will probably display incorrectly on the Mac. Crap! :(

That's a shame, because in many situations, PNG-8 will compress much nicer than JPEG and much better than GIF. But if you can't color match it with your CSS on all browsers, it's almost useless... :no:

Mac instead of PC for PHP/Web development?

I have recently put together a new Core 2 duo PC for doing my web development. And I have been asked why I didn't get a Core 2 duo Mac instead...

The question definitely makes sense. You can now get essentially the same components into a PC or a Mac. So the choice would boil down to:

  • Design
  • OS
  • Software


Well, the Macs look better, definitely.


If you choose your hardware carefully, you can get a pretty decent looking PC. Check out these Antec enclosures (they have a nice quality feeling by the way) or these Sony displays.

And also, if you actually want to connect 3 screens to a Mac, you'll definitely need one of those bigger Mac Pros where you can put in a PC video card. And those sort of lose their coolness factor over the iMacs. But to be fair, I guess you could get away with a 24" iMac ;)

Full story »