SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Questions about 301 redirect and other stuff

    Hi guys, nice website you have here. I have some questions about my small website. The site is for my contracting business, right now there are 5 pages but I will get it up to 10-12 pages soon. It's been active for a month.

    When I do a site:website.com search on Google it shows that the pages were indexed. But when I do a site:www.website.com search, nothing comes up. So apparently Google only indexed the non-www pages.

    I signed up for Google's Webmaster Tools, put both the www and non-www pages into my profile, and set the www pages to be the preferred.

    My question is what should I do now? Should I set a 301 redirect? If so, what exactly what I put into the .htaccess file? Which page should I redirect to, the non-www page which is currently indexed by Google or the www page which seems like the more proper thing to do?

    Again, the site is only about a month old and very small so I don't know if this stuff even matters much for me?

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,319
    Mentioned
    462 Post(s)
    Tagged
    8 Thread(s)
    Hi MechElec. Welcome to the forums.

    It's best to choose either the www or non-www version of your site, and redirect the other to the one you choose. It sounds like this may have been doen already, though. Can you view the www version of your site in a browser if you type it directly in? Not all web hosts create both versions ...

    If you can, then you still need to do the redirect. It's pretty simple code. This page shows code for both versions ("Force www" and "Eliminate www"): http://datakoncepts.com/seo

    Personally, I prefer the non www version, as www is a bit old hat and pointless, but it's up to you.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Hi MechElec. Welcome to the forums.

    It's best to choose either the www or non-www version of your site, and redirect the other to the one you choose. It sounds like this may have been doen already, though. Can you view the www version of your site in a browser if you type it directly in? Not all web hosts create both versions ...
    Yes, both work.

    If you can, then you still need to do the redirect. It's pretty simple code. This page shows code for both versions ("Force www" and "Eliminate www"): http://datakoncepts.com/seo

    Personally, I prefer the non www version, as www is a bit old hat and pointless, but it's up to you.
    I would prefer www., my main concern is that Google hasn't indexed that, only the non-www.

    Since I set the preferred to www in Google Webmaster tools and if I do the redirect, will I be ok?

    Thank you for the help!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oddly enough, I couldn't get it to work with the code from your link, Chrome gave me a redirect loop error. however, it worked with this code from another site:

    Code:
    Options +FollowSymLinks 
    RewriteEngine on
     
    RewriteBase /
     
    RewriteCond %{http_host} ^blahblahelectric.com$ [nc]
     
    RewriteRule ^(.*)$ http://www.blahblahelectric.com/$1 [r=301,nc,L]
    Everything seems to be working perfectly fine now. Is this code ok?

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    ME,

    Let me add a welcome to SitePoint, too!

    You tried

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]
    and it didn't work? Did you test that you have mod_rewrite enabled (as well as .htaccess)? The test is at the top of the page under Test.

    Alternatively,

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]
    will do the same thing. Both work.

    As for your other code:

    Code:
    Options +FollowSymLinks 
    # Already in the httpd.conf
    RewriteEngine on
     
    RewriteBase /
    # Undoes a mod_alias redirection and, here, is superfluous 
    
    RewriteCond %{http_host} ^blahblahelectric.com$ [nc]
     
    RewriteRule ^(.*)$ http://www.blahblahelectric.com/$1 [r=301,nc,L]
    # while it doesn't make sense to create an atom duplicating an Apache variable,
    # this, too, will work.
    # However, because {REQUEST_URI} is case sensitive,
    # the No Case flag is wrong.
    
    # Additionally, while it's strictly technique, it's better
    # to use CAPS for Apache variables and flags.
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    ME,

    Let me add a welcome to SitePoint, too!
    Thank you!
    and it didn't work? Did you test that you have mod_rewrite enabled (as well as .htaccess)? The test is at the top of the page under Test.
    I can't find this link anywhere :-( I'd like to test this out first.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind.

    I tried it using the following again and it worked this time. I don't understand why it didn't work yesterday, but I am glad that I got it working the correct way. Thanks!

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Hi ME,

    That wasn't a link but an <h2> tag on my seo page (see Article linked in my signature) which I use JS to generate a drop down link (because the page is excessively long).

    Anyway, I was shocked that it hadn't worked for you so I'm glad that you got the alternate version to work. Just remember that it will also redirect any subdomains that you may attempt to link to without any exclusions (read the article for sample code).

    Regards,

    DK

    Quote Originally Posted by MechElec View Post
    Thank you!
    I can't find this link anywhere :-( I'd like to test this out first.
    Quote Originally Posted by MechElec View Post
    Nevermind.

    I tried it using the following again and it worked this time. I don't understand why it didn't work yesterday, but I am glad that I got it working the correct way. Thanks!

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Hi ME,

    That wasn't a link but an <h2> tag on my seo page (see Article linked in my signature) which I use JS to generate a drop down link (because the page is excessively long).

    Anyway, I was shocked that it hadn't worked for you so I'm glad that you got the alternate version to work. Just remember that it will also redirect any subdomains that you may attempt to link to without any exclusions (read the article for sample code).

    Regards,

    DK
    I see, it all makes sense now. I didn't realize that you were the author of the page that Ralph originally linked me to and that you were talking about that page when you mentioned the test. Small world!

    Thanks again guys.

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    ME,

    No worries. I'd been a TL here for several years and had initially generated that tutorial article in an effort to save myself from Carpal Tunnel Syndrome and even allowed SP to use it as an article before I created the sticky at the front of the Apache (now Server) forum board. I can only keep my own page "up to date," though, so I still consider it the "master copy" (and try to post an "Updated" in my signature when appropriate).

    Anyway, you know who to attack for mod_rewrite problems as I still hang around here.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  11. #11
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by ralph.m View Post
    ...
    Personally, I prefer the non www version, as www is a bit old hat and pointless, but it's up to you.
    Off Topic:

    Recently I found a reason to enforce WWW over non-www. A client on a windows network hosted their own email. They had defined their public domain name as a zone file in their local domain. This was to allow them to resolve their email hostname. They define a WWW zone record so that the could resolve to their public external hosted website. In this case the customer could not resolve the non-www domain for the website as the default zone would answer and not pass it to the WWW record. By forcing WWW they and the public can see the website.

    I know that the DNS can be configured to resolve an A or CNAME record without WWW, but I did not have control of the DNS nor would they create these records.

    Yes somewhat unique case, but lucky to have the WWW to deal with this
    ictus==""

  12. #12
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    The hosts I've used have all created DNS records for both www and non-www versions of every (master and addon) domain within my account (probably a cPanel feature). While I prefer non-www, as far as I'm concerned, the only reasons to force one or the other are:

    1. Personal preference (a poor excuse to force something on a visitor, IMHO) and
    2. To match the security certificate for a domain (secure certificate authorities issue a certificate as you request, i.e., with or without the www so it's up to the webmaster to ensure that the appropriate www'd version is requested for the SSL to function as intended).


    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  13. #13
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,319
    Mentioned
    462 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by dklynn View Post
    the only reasons to force one or the other are ...
    The third one that's regularly raised is the idea that having the the site available at both www and non-www divides any search engine ranking value between the two versions of the site, lowering the overall findability of the site. I can only assume that this is true, given how often it is stated.

  14. #14
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Just to be clear, I also prefer non www now, but it is largely a personal choice, even though DK's and Ralphs's reasons are good ones
    ictus==""


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
  •