Using Apache and .htaccess

Today I will write some tricks that you can use with Apache’s .htaccess

Redirecting all except your IP. So you can develop the website or debug it.

ErrorDocument 403 http://www.keralpatel.com
Order deny,allow
Deny from all
Allow from YOUR-IP-HERE

How to setup a timezone for the server

SetEnv TZ Australia/Adelaide

How to force a file download

AddType application/octet-stream .avi .mp3 .wav .pdf

SEO friendly redirect to www. version of the website.

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^sitename.com [nc]
rewriterule ^(.*)$ http://www.sitename.com/$1 [r=301,nc]

Where sitename.com and www.sitename.com you can replace it with your own site name.

Redirecting a single page [SEO Friendly]

Redirect 301 /old/page.html http://www.keralpatel.com/new/page.html

Redirecting a whole directory [SEO Friendly]

RedirectMatch 301 /somefolder(.*) http://www.keralpatel.com/$1

For custom error pages with help of .htaccess refer to : Creating custom error pages for your site.

You Might Also Like