Jump to content

Recommended Posts

In all honesty, this isn't something that should be done in javascript, it should be done at the server level. The reason is that if you do it in javascript, the person will have to download the javascript, the javascript will then redirect the user, which will then send another request to the server, and the user will have to download the page, including the javascript from before, all again.

 

If it's done on the server side, the browser makes a request to the server, the server sees that the URL is wrong, and sends the user the data for the proper page. Much faster and better.

 

You can do it in an .htaccess file with the following:

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

(note: you will need to change both 'example.com' to your actual domain name)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.