Shopping Cart Forum

Go Back   eShop Forums - eCommerce Help Forum for Shopping Cart Owners. > Tech Corner > Servers
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Servers Servers and operating sytems talk.

15% discount
Reply
 
LinkBack (5) Thread Tools Display Modes
  5 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 26-10-2007, 02:21 PM
Lawrence Lawrence is offline
Forum Admin
 
Join Date: Aug 2007
Location: Kenley, Surrey, UK
Posts: 1,130
Thanks: 0
Thanked 65 Times in 65 Posts
Default How to 301 redirect non-www URLs to www ones and vice versa using .htaccess

Sometimes you may find that you have both www and non-www versions of your site e.g http://www.mysite.com & http://mysite.com indexed in the SERPs which not only looks messy but could possibly lead to your site being penalised for duplicate content. One method to prevent this is to use Apache's mod_rewrite to change the URLs.

This is how you would use it to change non-www to www

Code:
RewriteEngine On
 
RewriteCond %{HTTP_HOST} ^MySite.com [NC]
RewriteRule ^(.*)$ http://www.MySite.com/$1 [L,R=301]
and this is how you would do it in reverse i.e. change www to non-www URLs

Code:
RewriteEngine On
 
RewriteCond %{HTTP_HOST} ^www.MySite.com [NC]
RewriteRule ^(.*)$ http://MySite.com/$1 [L,R=301]
There's much more that can be done with Apache's mod_rewrite rules. To use them to their full potential, I'd recommend acquainting yourself with regular expressions for which you'll find many tutorials on the net.
__________________
Lawrence
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.eshopforums.com/f30/how-301-redirect-non-www-urls-www-ones-vice-versa-using-htaccess-632/
Posted By For Type Date
301 re-direct - Page 2 - UK Business Forums - business help and advice for owners, managers and entrepreneurs of small businesses and startups This thread Refback 20-02-2008 07:30 PM
Digg / Linux/Unix / Upcoming This thread Refback 27-10-2007 12:27 AM
Digg / Linux/Unix / Upcoming This thread Refback 26-10-2007 07:47 PM
Digg / Linux/Unix / Upcoming This thread Refback 26-10-2007 02:45 PM
Digg - How to 301 redirect non-www URLs to www ones and vice-a-versa. This thread Refback 26-10-2007 02:43 PM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use .htaccess to block IPs and domains from your website. Lawrence Servers 1 04-07-2008 10:40 PM
How to use mod_rewrite to block bad bots with .htaccess Lawrence Servers 0 30-10-2007 03:25 AM
How to perform a HTTP 301 redirect in PHP (Search engine friendly) Lawrence PHP/MySQL ASP.net and other server side technologies 0 29-09-2007 12:37 AM
How to do a page redirect using HTML meta tags. Lawrence HTML/XHTML CSS & JavaScript 2 26-08-2007 11:20 AM

Google

Edible Graphics, Affordable E-Commerce, Web Shops & Custom Form Scripts
Click here for domain name registration and web hosting
tech news, product reviews, the latest home and business technology, the latest in digital imaging


Content Relevant URLs by vBSEO 3.0.0