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?

Hi MechElec. Welcome to the forums. :slight_smile:

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.

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!

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:

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?

ME,

Let me add a welcome to SitePoint, too!

You tried

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,

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:

[COLOR="#FFA500"]Options +FollowSymLinks
# Already in the httpd.conf[/COLOR]
RewriteEngine on

[COLOR="#FFA500"]RewriteBase /
# Undoes a mod_alias redirection and, here, is superfluous [/COLOR]

RewriteCond %{[COLOR="#808080"]http_host[/COLOR]} ^blahblahelectric.com$ [[COLOR="#808080"]nc[/COLOR]]

RewriteRule ^(.*)$ http://www.blahblahelectric.com/$1 [[COLOR="#808080"]r[/COLOR]=301,[COLOR="#FF0000"]nc[/COLOR],[COLOR="#808080"]L[/COLOR]]
# while it doesn't make sense to create an atom duplicating an Apache variable,
# this, too, will work.
[COLOR="#FF0000"]# However, because {REQUEST_URI} is case sensitive,
# the No Case flag is wrong.
[/COLOR]
[COLOR="#808080"]# Additionally, while it's strictly technique, it's better
# to use CAPS for Apache variables and flags.[/COLOR]

Regards,

DK

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 :frowning: I’d like to test this out first.

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!

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

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.

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

[ot]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[/ot]

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

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.

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 :slight_smile: