Forum Moderators: mack

Message Too Old, No Replies

http://domain.com vs. http://www.domain.com

How do I 301 redirect in this situation?

         

bauer77

9:36 am on Jul 28, 2005 (gmt 0)

10+ Year Member



Googleguy had posted this message:

"Once you've picked a root page and decided on www vs. non-www, make sure that all your links follow the same convention and point to the root page that you picked. Also, I would use a 301 redirect or rewrite so that your root page doesn't appear twice. For example, if you select [yourdomain.com...] as your root page, then if a spider tries to fetch [yourdomain.com...] (without the www), your web server should do a permanent (301) redirect to your root page at [yourdomain.com...]

First off, I'm not sure of the exact coding to do this. Examples on the web say to create a .htaccess file with coding like this:

redirect 301 /old/old.htm [domain.com...]

but not to use http:// in the first section after "redirect 301". If not, how exactly do you create the redirect that Googleguy suggests?

Also, on my web stats, I'm showing some requests for all of the "non-www" address versions of the pages in my site. Should these be 301 redirected too, or should I not worry about anything but my root page?

Thanks,
Mike

mack

9:06 am on Jul 29, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month




RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Hope this helps.

Mack.

bauer77

10:02 am on Jul 29, 2005 (gmt 0)

10+ Year Member



Thanks for replying, Mack.

I copied the three lines of text you provided, changed "example" to my domain name in both lines, placed it in a plain text document, named it ".htaccess" and placed it on my ftp server. When I open a browser page and type in "http://mydomain.com", though, it doesn't redirect to "http://www.mydomain.com".

Could it be something on the hosting side that's not allowing it? (I'm using godaddy)

Thanks,
Mike

mack

10:48 am on Jul 29, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



grrr bad news i'm afraid.

It appears godady allow users to use the htaccess file, but do not allow you to use mod_rewrite

I am not sure if this applies to all of their hosting options, it may be worth dropping them an email to check.

Sorry.

Mack.

bauer77

9:07 am on Aug 1, 2005 (gmt 0)

10+ Year Member



Hi Mack,

I emailed back and forth a bit with godaddy support, and they said that mod_rewrite was currently supported on their Linux-based hosting packages, which I have (Linux: PHP). Does that help?

Thanks,
Mike

j4mes

9:16 am on Aug 1, 2005 (gmt 0)

10+ Year Member



Just tested that rule with my own server and (of course, thanks mack) it works perfectly.

Is there any chance they're lying?

twist

2:42 pm on Aug 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your website has it's own IP address you should redirect that also.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^192\.168\.127\.1¦www\.example\.com¦example\.com\.$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=permanent,L]

As for godaddy, probably against TOS to say this, I signed up for their hosting service to see if it was any good. I decided to go for one month with the $10 package. They have a drop down box when your signing up on page one whether you want ASP/PHP. After going forward and backward through their horrendous signup process stuffed with ads I accidently got stuck with ASP. So I thought I would simply change it in their control panel. I couldn't find any way to change it. My choices would be to call them long distance and ask or email and maybe get a reply in a day. I figured this was a sign from gawd that I should just cut my losses. I cancelled my account five minutes after signing up. I lost my $10 but look at it as a lesson learned in cheap hosting.

jdMorgan

2:58 pm on Aug 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two possible fixes for your problem:

First, always flush your browser cache (Temporary internet files) aftet making *any* changes to your configuration or access-control code. This forces the browser to send your request to the server where your code can have some effect, rather than serving your request from its locally-cached copy of the page.

Second, you may need to add the line


Options +FollowSymLinks

ahead of the code posted above. If not already set by your hosting company in your server's configuration, this will be required in order to enable mod_rewrite, as stated in the documentation [httpd.apache.org].

So with that and a few other fixes and speed-up tweaks, you get:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com¦192\.168\.127\.1 [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]

In some cases, attempting to add this Options line may cause an error if your host has already set it up and does not allow "users" to change Options settings.

Change the broken pipe "¦" character above to a solid pipe before attempting to use this code; Posting on this forum modifies that character.

Jim

bauer77

8:57 am on Aug 3, 2005 (gmt 0)

10+ Year Member



Thanks everybody, finally got it working properly.

And yes, I'm finding that godaddy leaves a lot to be desired as far as hosting (particularly their phone support, email gives much better results)

Live and learn...