Knowledgebase

Apache mod_rewrite

So, in order to make your website more SEO friendly, and provide cleaner, easier to read URLs, you want to enable mod_rewrite on your hosting account but are not sure how exactly to "switch it on" as there arnt any buttons in cpanel for it.

Well, its extremely simple, but because it controls apache's behaviour, we would advise you NOT to use this at root level if you have any addon domains that also need it.

Heres what you do:

1) Create a new empty plain text file somewhere "untitled.txt" for example on your desktop.

2) Insert the following into that text file: "RewriteEngine on"

3) Now you need to save the file and rename it, in its entirety to ".htaccess" ensuring it starts with the fullstop.

4) Now simply upload the file to the root of your website, such as "public_html" and it will enable you to add any apache rewriting commands to that file to control the output of your URL's

A typical example, nice and easy is the 301 redirect, redirecting a parked domain to the live domain like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^wesh.co.uk
RewriteRule ^(.*)$ http://www.wesh.co.uk/$1 [r=301,L]

That would rewrite the URL in the address bar for anybody trying to access wesh.co.uk WITHOUT using the "www" in the address, to force the URL to its full and correct setup.

Some further help:

Apache URL rewriting guide // mod_rewrite // Google search results

  • 98 Users Found This Useful

Was this answer helpful?

Related Articles

Errors relating to Magic Quotes

If your getting error messages relating to "Magic Quotes" when using or programming in PHP, or...

Creating PHPinfo files

When you first setup your hosting account with you you will probably want to see whats...

open_basedir restriction in effect

If you are trying to use your temporary URL provided in your welcome email and are getting error...

Path to PEAR and PEARDB

Your path to PEAR on all servers is: /home/cpanelusername/php (Replacing "cpanelusername"...

Perl version & Path to Perl & Sendmail

If you need to find out the Current Versions and Paths to both Perl and Sendmail then simply...