Apache mod_rewrite Print

  • 98

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


Was this answer helpful?

« Back