Roshan Book

My Tech Notebook

Tag Archives: .htaccess

Redirecting non-www to www with .htaccess

Source :

If you want to redirect all non-www requests to your site to the www version, all you need to do is add the following code to your .htaccess file:

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

This will redirect any requests to to There are several benefits from doing that:

  • It will avoid duplicate content in Google
  • It will avoid the possibility of split page rank and/or split link popularity (inbound links).
  • It’s nicer, and more consistent.

Note that if your site has already been indexed by Google without the www, this might cause unwanted side effects, like lost of PR. I don’t think this would happen, or in any case it would be a temporary issue (we are doing a permanent redirect, 301, so Google should transfer all rankings to the www version). But anyway, use at your own risk!

Something nice about the code above is that you can use it for any website, since it doesn’t include the actual domain name.

Redirecting www to non-www

If you want to do the opposite, the code is very similar:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

In this case we are explicitly typing the domain name. I’m sure it’s possible to do it in a generic way, but I haven’t had the time to work one out and test it. So remember to change ‘my-domain’ with your domain name!

Increase activeCollab upload limit using htaccess

for activecollab



From hostgator


To increase the upload file size limit on your website, you need to edit PHP’s configuration settings. Unfortunately, not everyone has their own web server, so most of the time people are constrained by the limits of shared hosting. But you can still modify your base php.ini file by creating your own php.ini with the edits that you want.

Your php.ini file needs to be in every folder that’s going to be affected, or at least in the folder where the php script is being called from. Unfortunately if you have dozens of folders that need this edit, then you’ll need dozens of php.ini files.

An alternative is to then use .htaccess. By just placing a.htaccess file in your root folder, all folders beneath it will also have the change. The code to change your PHP max file upload size is:

RewriteEngine On
php_value post_max_size 1000M
php_value upload_max_filesize 1000M
php_value max_execution_time 6000000

You can edit it to suit your needs. 1000M = 1GB, so edit accordingly. Do note that your host will need to allow PHP edits though.





%d bloggers like this: