Forum Moderators: phranque

Message Too Old, No Replies

Brand new site, trouble with canonical 301

         

buckmajor

3:06 am on Nov 3, 2009 (gmt 0)

10+ Year Member



Hi there

I have a just built my site, and been trying to use the 301 for WWW/NonWWW Header CHECK. At the moment, it is still showing (FAILED), and want to avoid the duplicate content penalties. I have searched online, and on this forum, but nothing seems to work.

My website is not complete or finish yet, so I have a landing page, coming soon . This is just normal (.html) for now. But my site is a blog, so it is basically built in wordpress and there will be constant updates.

These are the following .htaccess code that I have tried, and all of them returned as 'Authentication Required', requesting a Username and Password for some reasons:
1.
-------
RewriteEngine on
#
# Externally redirect direct client requests for "/index.php" to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
# Externally redirect non-canonical, non-blank hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
------
2.
------
RewriteEngine On
RewriteBase /
RewriteRule ^example\.html$ http://www.example.com [R=301,NC,L]
------

Have I misunderstood what the 301 redirect?

Please help me, not sure where to go from here.

Many thanks in advance
CHEERS ;)

TheMadScientist

7:48 am on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have I misunderstood what the 301 redirect?

No, your code actually looks fairly good...
(I think you'll want to adjust to jdMorgans 'remove the index.ext' file from all directories (posted all over the place here) eventually, but for 'testing' and 'getting it working' I'm not seeing any issues.)

I have not received what you are talking about where authentication is required, so I cannot tell you exactly what to do, except for what I would do if faced with the same situation.

1.) Make sure you don't have any password protected directories / pages you are trying to redirect to. (I know it seems like a 'no-brainer' and I personally don't use this type of protection, so I don't ever have it set to on, but some do, so I have to say double check.)

2.) Make sure you have the ability to use mod_rewrite.
IOW Make sure it's loaded on your server I use something like:
File:
test.php

Contents:
<?php phpinfo(); ?>

Open test.php in a browser and scroll to the loaded modules section.

3.) If Mod_Rewrite is loaded, add:
Options +FollowSymLinks -MultiViews

To your .htaccess file preceding the RewriteEngine on.
(If you get a 500 error from this line, remove -MultiViews and try again...)

4.) Make sure you can perform a basic redirect:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^test\.html$ http://www.google.com/ [R=301,L]

Visit /test.html on your site and see if you land the Google 'fading home page' or the regular one... (If you don't land on some version of google.com then something's wrong.)

5.) Make sure you empty your browser cache before you refresh every time and double check 'all the little things' ... I had a situation where I was building a site (for myself), changed from index.html (provided by the host) to index.php (mine), deleted index.html from the server, because it's defaulted to before index.php, had Options -Indexes in my .htaccess, forgot to upload index.php before refreshing, and spent an hour looking at the screen and messing with the .htaccess file trying to figure out why I was getting a forbidden error. LOL. Options -Indexes and no index.ext file on the server gives you a forbidden error every time... Go figure... It worked great as a matter of fact. LMAO. (I think I tried to fire myself twice that day, but there was no one to fill my position so I had to settle for an hour of work with no pay.)

g1smd

8:44 am on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One minor point.

Make sure that

RewriteEngine On
appears only once in the file, and that it precedes all code that it applies to.

buckmajor

4:08 am on Nov 5, 2009 (gmt 0)

10+ Year Member



Ureeks! I got it going, it is a perfect score.

I apologize for the delay. As you can see, I trying for ages, and still nothing working. Until, I tried something, and it worked. The server or hosting that I am with, had a authentication username and password with my .htaccess. So removed that code and it worked with this:
-------
RewriteEngine on
#
# Externally redirect direct client requests for "/index.php" to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
# Externally redirect non-canonical, non-blank hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^test\.html$ [google.com...] [R=301,L]
-------

I had to change my file (.html) to (.php) to use this code. Cause I didn't know what code to use for html redirect.

I'm very happy and over the moon about this. Now I know what to do with a new website and a perfect score for Duplicate Content. Yehaa.

Thanks heaps guys. Man, if it wasn't for geniuses like you and me (na kidding, just you guys), how would this world go around ;).

CHEERS :)

TheMadScientist

4:15 am on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A little adjustment for you:

(You only need RewriteEngine on once, and the Options directive is part of the Apache Core Features, so it does not need to go anywhere near the mod_rewrite code in the file.)

Options +FollowSymLinks -MultiViews
RewriteEngine on
#
# Externally redirect direct client requests for "/index.php" to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
# Externally redirect non-canonical, non-blank hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteRule ^test\.html$ http://www.google.com/ [R=301,L]

* And, to use it with .html, simple change the \.php to \.html in the first rule and condition... Glad you got it working :)

buckmajor

4:40 am on Nov 5, 2009 (gmt 0)

10+ Year Member



Thanks TheMadScientist, sweet then, so all need to do is change the extension. Cool! I will keep this for future reference.

Too easy], thanks again