Making your PHP code work within files with extension .html

August 1st, 2010

By default your php code will only work if the file is named .php but if your files have extension .html or .htm and you would like them to be able execute php code as well, you would need to make a small change to .htaccess

Just add the lines below in .htaccess file and you would be able to execute php in html files

RewriteEngine on
AddHandler application/x-httpd-php5 .html .htm

Related Articles:
1. Redirecting your non www domain.com to www.domain.com using .htaccess

Prevent your directory from being viewed when Index file is absent

May 26th, 2010

When you make any new directory or folder under your hosting and it does not have any index page, you are able to see the directory structure or a list of all files available on that folder. To prevent this from happening, you can either put up a blank index file or use .htaccess rules to hide the folder content thought-out your website. Please have a look at this comprehensive article if to make this happen using .htaccess. How to Prevent a Directory Listing of Your Website with .htaccess

Redirecting your domain.com to www.domain.com

April 19th, 2010

With people taking steps to make their website search engine friendly, there are some basic things which can be done to get on the better side of Google. Redirecting non www domains to www domains avoids the issue of duplicate content being indexed on search engines.

Below is the code which you need to put in your .htaccess which will redirect any user who types in yourdomain.com to www.yourdomain.com

RewriteEngine on

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

Please change example.com to your website url.

How can i redirect Root to a Folder on my hosting?

February 7th, 2010

Using .htaccess you can very simply redirect your root to a folder on your website. For e.g. when someone would type example.com they would be automatically be redirected to example.com/folder/index.html

To do the above, please add the following line in your .htaccess

RedirectMatch permanent ^/$ http://example.com/folder/index.html

Please replace example.com and folder with your hosting details.

Redirect Main Domain to Sub Domain using .htaccess

January 22nd, 2010

There are two simple ways to redirect your main domain to any sub-domain.

1. Using php / html redirect
2. Using .htaccess

In this article i will show you how to redirect using .htaccess. If you already have an .htaccess file in your root folder then open to edit it, else create a new one using note pad and then cut and paste the code below.

Note: Please change the url to your own domain name.

RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC] 
RewriteRule ^ http://subdomain.example.com [R,L]

Related article:
1. How to Redirect a folder to a Subdomain using .htaccess