Hints and tips on web_design

These are some helpful hints on various topics.


Adding www to domain name

If you want you users and search bots to be redirected from http://domain.com/some-page.html to http://www.domain.com/some-page.html for any page some-page.html add the following code to you .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteRule .* http://www.domain.com%{REQUEST_URI} [L,R=301]

Short closed <script> tags may not work in Internet Explorer 6 (IE6)

Short script tags like <script src="file.js" /> do not work in IE6.
You should use <script src="file.js"></script> instead.

Erorr "400 Bad request" when using mod_rewrite

Sometimes when you use mod_rewrite you get "400 Bad request" error, when accessing directory  without  trailing slash. For example http://domain.com/forum returns "400 Bad request" when forum is directory while http://domain.com/forum/ has normal response. To fix this issue use this fragment in your .htaccess file:

RewriteCond    %{REQUEST_FILENAME}  -d
RewriteCond    %{REQUEST_URI}  (.*)
RewriteRule    (.+)[^/]           %1/  [R=301,L]

HTTP headers for disabling browser cache

    header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
    header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
    header( 'Cache-Control: no-store, no-cache, must-revalidate' );
    header( 'Cache-Control: post-check=0, pre-check=0', false );
    header( 'Pragma: no-cache' );

Auto generation of current year in copiright message of the website

Most websites have similar notice in their footer:

Copyright 1995-2010 example.com

The problem is that you have to change the current year every year. Here's how to do it with PHP:

Copyright 1995-<?php echo date('Y') ?> example.com