Archive for October, 2008
Twitter…
…or xkcd is inspired today
I guess a link to explain Burma Shave is necessary. Tom Waits made me wonder with his song.
.htaccess tips and tricks
Posted by admin in Web design & development on October 24, 2008
Rewrite
We *heart* canonical URIs
[Note - I've recently come accross a web hosting company that disallows Options +FollowSymLinks. When used their server throws an internal error page - you may need to replace with the more secure (on shared hosting systems anyway) Options +SymLinksIfOwnerMatch ]
Get rid of those pesky Ws.
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www.example\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://example.co.uk/$1 [R=301,L]
Or as you may well prefer – reinstate them
The SEO boys, they say “www“.
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^example\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]
…rewrite continued:
#redirect all .html pages to .php
RewriteBase /
RewriteRule ^(.*).html$ $1.php [R=301]
Redirects
#specific page redirects - PERMANENT
redirect 301 /example-page.html http://example.com/new-name.html
#specific page redirects- TEMPORARY
redirect 302 /example-page.html http://example.com/new-name.html
Spell checker
Thanks to Jens Meiert This little line will allow a single typo in your users’ URIs (guess who just discovered that “URL” is a depreciated term):
CheckSpelling On
Get rid of any instances of “index.html”. And more
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^/]+/)*index.(html?|php) HTTP/
RewriteRule ^(([^/]+/)*)index.(html?|php)$ http://example.com/$1 [R=301,L]
Add trailing slashes where they may have been missed…
Thanks to Webmaster World
# If final URL-path-part does not contain a period or end with a slash
RewriteCond %{REQUEST_URI} !(\.[^/]*|/)$
# Redirect to add a trailing slash
RewriteRule (.*) http://www.example.com/$1/ [R=301,L]
more…
Set PDFs to download rather than open in browser
#option for PDFs to download rather than open
AddType application/octet-stream .pdf
Disable directory browsing
# disable directory browsing
Options All -Indexes
Redirect denied directory listings etc to standard error page
# redirect denied directory listings etc to standard error page
ErrorDocument 403 /404-redirect.html
ErrorDocument 404 /404-redirect.html
Ease versioning of CSS files (+)
Will also improve history viewing with GitX
Note: this assumes a naming convention of, for example /css/filename.1234.css. Other dots will break this fragile little fellow.
#Rules for Versioned Static Files
RewriteRule ^(scripts|css)/(.+)\.(.+)\.(js|css)$ $1/$2.$4 [L]
Random content rotation using PHP
Posted by admin in Web design & development on October 22, 2008
I had been using a JavaScript solution from javascriptkit.com to randomly show one option from a series on a page. All the options are wrapped in DIVs and placed in a single include file. This first solution used JS to set a CSS display:none; to all but one of a series of DIVs in a document. Nice as it was, the resulting xHTML markup would not validate properly. [UPDATE - this is due to the fact that xHTML needing extra CDATA markup around any JavaScript contained within.] Another minus was that, although sold as plus for web-crawlers etc (all options remain in the HTML at all times), if JavaScript was off then all of the options would appear and muck-up the carefully honed design.
I looked for fixes to the validation issues caused by this line for (var i=0; i<alldivs .length; i++) but to no avail. Half a day of searching later and after trying these other options I found the answer;
CSS and Perl solution by Nigel Pecksimilar in method to my first option- a seemingly super simple PHP solution from Greta in the comments to the above (requires splitting the options into separate files)
- a php solution from
pixel2life.com
The Answer
None of these worked for me. The best (only) solution I found before the sun went down was from Joe Crawford. Based on PHP’s srand function
this solution allowed me to wrap PHP around the include file with the options and bingo; it works. As this is server side now – only one DIV will be in the HTML so no problem if JavaScript is off.
Happy.
Full alpha transparency for PNG images and CSS backgrounds in IE6.
Posted by admin in Web design & development on October 18, 2008
Update 2009
I’ve now jumped to the other side of the fence. In the name of speed and slowly [oh so slowly] dying share of IE6 I’ve stopped trying to pander to it. There’s a few extra bugs and issues to contend with anyway. So what I’ll do now is specify a regular gif or PNG8 file in an for IE6 using a selector hack. Anyway – for posterity here’s the old articl
Have nice PNG with transparency. Wish to implement. Must consider IE6. Nasty, distinctly non-transparent grey background for PNGs in IE6.
Current job requires a PNG implemented as a CSS background which repeats on all pages of the site…
If-already-then-already — the search was on to find a solution that works on CSS background images and regular in-line images. That and it had to be a nice standards compliant thing with a low footprint.
Jump to the best options and/or the conclusion
Googled it. Solutions I found and tried first:
supersleight– couldn’t get it to work at-all at-all.unitpngfix– worked well – but if image is reused (cached) on a different page then image suffers from a flash of the nasty grey. That and there are positioning issues.ie7– works as unitpngfix – also does other things I’m not too interested in. No want the flashy flashy grey.
Then, on having another look a the long wiki list of other possible options, – eureka! I realised I really should be using IE6 itself as the first test. [Still not used to having IE6 on my mac!] Most of these have an on-line demo! Brilliant. What a clever chap. [A-hem.] OK – it’s late, forgive me please…
With intelligent filtering™ now in place I found that most of the solutions suffer from the grey/gray flash. Of these not-so-rans Flixn suffers the grey flash but at least positioning is good.
The Best Options
In the end the fix comes in the shape of IE’s proprietary image filters; DirectX weirdness over a ten-year-old standardised graphic format. “Go figure.” Anyway most of the fixes available use this feature but only two options pass the grey/gray flash test*:
- “pngbehavior” from webfx
- “Cross Browser PNG Transparency” parts one and two from drunkenfist
pngbehavior
Great! Just add a CSS class to your inline images, one CSS declaration (non-standard) and throw a lovely pngbehavior.htc. Bingo. But this only works on inline images – not with CSS background images…
“Cross Browser PNG Transparency” from drunkenfist
Perfect with CSS background images but more work than pngbehavior for inline images as requires an extra named div and then two lines of CSS per image. Great point from this chap about using the conditional comments and separate style sheets to hide IE specific CSS hacks from other browsers.
Conclusion
OK – so neither of the best options fulfil the requirement to fix PNG24 images and CSS backgrounds nicely but can drunkenfist and pngbehavior work together? YES!
Me, happy? Yabetcha.
CSS goes something like this:
/* TRANSPARENT PNGs IN IE6 */
/* For background images (from from http://www.drunkenfist.com/304/2007/04/04/cross-browser-png-transparency-part-2/ ) NOTE THE FIRST background:url() IS BLANK. LEAVE IT SO! */
#YourID {
background:url();
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='
/path/to/image.png',sizingMethod='crop');
}
/* For inline images (from http://webfx.eae.net/dhtml/pngbehavior/demo.html
) */
img.png {
behavior: url("/path/to/pngbehavior.htc");
}
Wrap all this IE gubbins into a single CSS file and link via a conditional comment to hide your shame (and keep things ‘validatable’ of course).
Said conditional bit to put in your head:
<!--[if gte IE 5.5]>
<![if lt IE 7]>
<link rel="STYLESHEET" type="text/css" href="/path/to/ie-gubbins.css" />
<![endif]>
<![endif]-->
Don’t forget that pngbehavior.htc file from webfx.
I tried
Cache fix for CSS and JavaScript on a live site
Posted by admin in Web design & development on October 7, 2008
Update
Well in the end I couldn’t get this to work. Too noob. So I’ve settled on old school versioning. Not really an issue in the end as the extra overhead (working on a duplicated and renamed the CSS file) is no big deal.
KISS.
CSS caching was an issue waiting to jump out at me. In the end it’s covered.
.htaccess has whooped my ass again – but I’ll be back.
Great tip from Ask Apache. This one is a couple of tips down from here. A real beauty. Imagine working on a live site – you’re just updating your CSS – but this is cached. Now you change the include file which has your HTML head calling yours CSS file. Bingo – site-wide updated CSS. Brilliant.
Pasted here for posterity.
Cache-Friendly File Names
This is probably my favorite, and I use it on every site I work on. It allows me to update my javascript and css files in my visitors cache’s simply by naming them differently in the html, on the server they stay the same name. This rewrites all files for
/zap/j/anything-anynumber.js to /zap/j/anything.js and /zap/c/anything-anynumber.css to /zap/c/anything.cssRewriteRule ^zap/(j|c)/([a-z]+)-([0-9]+)\.(js|css)$ /zap/$1/$2.$4 [L]
Multiple virtualised XPs with IE6, 7 and 8 for development testing with a Mac, VMWare and VHDs from Microsoft
Posted by admin in Web design & development on October 3, 2008
As IE can only work reliably in exclusion of other versions. the most (or only) reliable way to test various versions of IE on one machine is using virtualization. Amazing but oh-so-true.
VPC images for ie6 ie7 and ie8 for web development and testing from Microsoft
Microsoft give away free time crippled VHD files for this purpose – search for “Internet Explorer Application Compatibility VPC Image”. Today you will find this link here. Look at that link – SEO urls a-go-go! Gone.
Problem is that getting these images to play nice with VMWare Fusion for Mac is not so straightforward. The only way I’ve found to do this is documented here on the VMWare communities. The result — at least without the required XP Pro install disk which I have packed away in a box somewhere — is pretty good. Not as seamless as the original VirtualPC image I converted but very usable.
An aside… on forcing IE8 to be backwardly compatibile with IE7
…is via a metatag in the head element to ask it nicely to behave like IE7:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
DON’T BREAK THE WEB! They cried. I think there’s ironing in there. Nice starch.
