Jump to content

redirect pages to www using javascript


shaam

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.