E-Commerce Newbie

How to start an online business


Htaccess Tricks

Having trouble getting your website to work just the way you want? Here are a few simple htaccess tricks you can use to perform some basic tasks.

FTP into your site or use file manager in Cpanel, your .htaccess file will be located in your sites root folder. You may not have a .htaccess file if you don't see a file named .htaccess you can easily create one using notepad.

Open Notepad add the lines of code you want & save it as .htaccess then upload to your root directory.

Simple .htaccess redirect code

Redirect pagetoredirect.html /redirect.html

or Off Site Redirecting

Redirect pagetoredirect.html http://site.url/page.html

NOTE: You can use the off site redirecting for affiliate links

301 Redirect

redirect 301 /olddirectory/oldpage.htm http://www.yoursite.com/newpage.htm

Good for republishing existing sites with different page names

Displaying PHP includes in .htm & .html pages. 

AddType application/x-httpd-php .php .html .htm
AddHandler application/x-httpd-php .htm .html

Some servers require the php version as well

AddType application/x-httpd-php5 .php .html .htm
AddHandler application/x-httpd-php5 .htm .html

Custom error code redirects

ErrorDocument 400 /yourcustom400page.html
ErrorDocument 401 /yourcustom401page.html
ErrorDocument 403 /yourcustom403page.html
ErrorDocument 404 /yourcustom404page.html
ErrorDocument 500 /yourcustom500page.html

You can add more lines & errors if you wish - Remember to create & upload your custom error pages first.

Tidy public_html

As you build your website you will create sub folders for content & for various programs you may install.

You will also generate sub folders in your public_html folder for all Sub domains & Addon domains, to say the least your Public_html folder will become very cluttered & it becomes harder & harder to distinguish between your site & the other domains.

An easy way to avoid this issue is by creating another folder in your public_html folder either using ftp or File Manager. Name the new folder after your main Domain Name.

Add a .htaccess file into your public_html then add the following code:

# Turn on rewrites.
RewriteEngine on

# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$

# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/newfolder/

# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ /newfolder/$1

# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteRule ^(/)?$ /newfolder/index.html

Modify the bold script to match your site. This will make the sub folder appear as if it is your public_html folder.

As you add more web sites (addon domains) the domain folders will be neatly installed alphabetically in your public_html folder

To ensure you keep you sites organized in the future you need to take care when adding subdomains - Subdomains are usually created outside of the parent domain folder by default. For better organization it is better to change the install path of your subdomains to inside the domains root folder.