Page 1 of 1

mod_rewrite and SEO

Posted: Thu Feb 23, 2006 1:32 pm
by intellivision
For months I had pages like

domain.com/page?p=1&q=2

that got indexed by Google and the other engines.

Then with the help of fine folks on this forum I mod_rewrite(d) them to

domain.com/page/p/1/q/2

Even better. But...

Question: now the engines will see duplicate content, yes?

If so, should I implement 301 (SEO-friendly) redirects of the original pages to the new urls?

If so, how? Am I overanalyzing this?

TIA

Re: mod_rewrite and SEO

Posted: Thu Feb 23, 2006 2:04 pm
by Chris Corbyn
intellivision wrote:For months I had pages like

domain.com/page?p=1&q=2

that got indexed by Google and the other engines.

Then with the help of fine folks on this forum I mod_rewrite(d) them to

domain.com/page/p/1/q/2

Even better. But...

Question: now the engines will see duplicate content, yes?

If so, should I implement 301 (SEO-friendly) redirects of the original pages to the new urls?

If so, how? Am I overanalyzing this?

TIA
You mean the search engines will see ?p=1&q=2 as well as /p/1/q/2 ?

Providing you correctly updated the links on the website to point to the new URLs this shouldn;t happen since the engines will have nothing to spider the old style URLs. Eventually the old links will disappear from the search engines ;) Basiscally, as long as everything's converted just wait :)

Posted: Thu Feb 23, 2006 3:09 pm
by josh
I'd say otherwise, if the search engines can still see the old pages (it already knows the URLs) it will keep them in the index. In your mod_rewrite add another GET variable like rewrite=1, if that variable is not there on the page then do a header redirect, googlebot should see the redirect and drop the old url eventually

Posted: Thu Feb 23, 2006 11:31 pm
by intellivision
jshpro2, I understand the concept, but isn't that kinda defeating the purpose of mod_rewrite and having a shorter URL?

Could I do it the other way around, where the old querystring gets the additional name-value pair?

Posted: Thu Feb 23, 2006 11:58 pm
by josh
intellivision wrote:Could I do it the other way around, where the old querystring gets the additional name-value pair?
And call up google and tell them to change the URL in their database to include this flag for you? No.


Also it is not defeating the purpose of mod_rewrite at all. The URL your users see is independant of a flag that you set on the GET string internally..

Posted: Fri Feb 24, 2006 12:08 am
by intellivision
Let me try to restate what you said to get this straight.

In the .htaccess file, add a line of code that appends "&rewrite=1" to the rewritten URL.

page/p/1/q/2&rewrite=1

Correct?

if that variable is not there on the page then do a header redirect

page?p=1&q=2

will get a 301 redirect then. Correct?

Posted: Fri Feb 24, 2006 12:20 am
by josh
Instead of

rewriteRule /test/([0-9]+) test.php?id=$1

do


rewriteRule /test/([0-9]+) test.php?id=$1&flag=1



Then in test.php

Code: Select all

if (!$_GET['flag']) {
header('Location:/test/'.(int)$_GET['id']);
exit();
}

Posted: Fri Feb 24, 2006 1:50 pm
by intellivision
Excellent, thank you, it worked.

I'm going to add one thing when I get home to make it perfect:

Code: Select all

header("HTTP/1.1 301 Moved Permanently");
before header('Location...

because without that line you'll get a non-spider-friendly 302 redirect: HTTP Status Code: HTTP/1.1 302

You may check your redirects with this:
http://www.seoconsultants.com/tools/headers.asp

Posted: Fri Feb 24, 2006 2:11 pm
by josh
Yep, I assumed you knew what you were doing so I didn't bother explaining that part...

Glad everything worked out