SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist happyoink's Avatar
    Join Date
    Jan 2008
    Location
    UK
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 redirect help please

    I am about to start designing my new portfolio site and I am using Google's WMT. I wanted to know how to sort out the preferred domain issue and the pros/cons of using the www part or doing without it.

    This thread I found helped a lot but I don't know anything about redirects. So I've followed the instructions in this thread (apart from the .htaccess file which I'm about to do). I found the following code in the thread I've linked to, butI prefer typing the URL without the www part and have set it accordingly in WMT and I'm not sure if this code will redirect users/crawlers from the www version to the non-www version of my site or if it does it the other way around. Can someone please tell me if I need to alter the code below to redirect users/crawlers from the www version to the non-www version?

    Quote Originally Posted by tomovuk View Post
    The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^domain.com [nc]
    rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

  2. #2
    Motivated Procrastinator seriocomic's Avatar
    Join Date
    Jan 2003
    Location
    Outside the bubble
    Posts
    1,275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code forces all requests to use the 'www' version.

    I used to have that approach (I thought that the 'www' was largely redundant and was swayed by sites like no-www.org), but now, with more knowledge and a desire to use smart cookie-less sub-domains for static resources such as images, CSS and JS, I switched to the 'www' variant.

    You DO have to be careful with .htaccess, as you can end up doing some spooky stuff that gets hard to trouble-shoot with regex.

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    From www to non-www would be

    Code:
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
    RewriteRule .? http://domain.com%{REQUEST_URI} [L,R=301]
    (also fixed some errors that were in there ...)
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Evangelist happyoink's Avatar
    Join Date
    Jan 2008
    Location
    UK
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much both of you.

    @ScallioXTX
    Just curious. I've been digging around in cPanel and I see that I can manage the 301 redirects from www to non-www (and vice versa) from there but if I did that from cPanel, would it make all the search engines do what they guys were talking about in the thread I linked to? Or would it be better for me to use the updated code you've just posted?

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    So long as it's a 301 redirect (not a 302!) you should be fine as far as link juice is concerned
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    SitePoint Evangelist happyoink's Avatar
    Join Date
    Jan 2008
    Location
    UK
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent! I think that would be an easier way for me to do it because I don't know anything about writing code for .htaccess. When I was fiddling around with the hotlinking protection in cPanel, after I'd copied and pasted the code you posted in my .htaccess file, cPanel displayed an error to do with the code. So I think I'll do it through cPanel instead. But thank you for helping me out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •