mod_rewrite and SEO

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

mod_rewrite and SEO

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: mod_rewrite and SEO

Post 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 :)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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..
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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();
}
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post 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
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Yep, I assumed you knew what you were doing so I didn't bother explaining that part...

Glad everything worked out
Post Reply