Hints and tips

These are some helpful hints on various topics.


1 2 3 4 5 6

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]

MSQQL count(columnt) doesn't support all data types

In MSSQL queries like

select count(col1) from table1

will fail if column type is uniqueidentifier, text, image, ntext. Those types are not supported also in aggregate functions and subqueries.

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.

PHP's safe mode automatically applies escapeshellargs to the argument of exec()

When safe mode is on you may have problems with function exec(). As PHP applies automatcally escapeshellargs() this makes exec($cmd) work like exec(escapeshellargs($cmd)). If you application already escapes the command, you will get double escaped thus invalid command. For example:

exec('convert  -resize ">10x10"  img.jpg') - fails, because command that is executed is convert  -resize \">10x10\"  img.jpg
exec('convert  -resize >10x10 img.jpg') - normal execution of command convert  -resize \>10x10 img.jpg

Also you cannot redirect program's stdin, stdout, stderror, because ">" and "<" are escaped:

exec('who > file.txt') - fails, trying to execute who \> file.txt

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]

1 2 3 4 5 6