Welcome to WebmasterWorld Guest from 54.163.61.66

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

using htaccess to avoid duplicate content

     
8:26 am on Feb 10, 2010 (gmt 0)

New User

5+ Year Member

joined:Feb 10, 2010
posts: 20
votes: 0


Hello,

I have problem with duplicate content on my web. I would like to solve it with htaccess.

So, I have
www.domain.com/new.php?id=6
www.domain.com/new.php?id=006
with the same content. I would like to redirect first URL to second URL with 301 status code.

Also for
www.domain.com/new.php?id=36
www.domain.com/new.php?id=036

Is this possible to do automatically, through some conditions in htacess?
1:12 pm on Feb 10, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Yes. After reviewing the mod_rewrite documentation and the other resources cited in our Apache Forum Charter, and the example threads in our Apache Forum Library, please post your best-effort code as a basis for discussion.

Links to these resources are at the top of this page.

In general, use a RewriteCond examining %{QUERY_STRING}, and back-referencing the query in your RewriteRule after stripping it of leading zeroes.

Thanks,
Jim
4:01 pm on Feb 11, 2010 (gmt 0)

New User

5+ Year Member

joined:Feb 10, 2010
posts:20
votes: 0


I am really trying to find some similar problem here on the forum or on the internet, but without success until now. Can you please at least navigate me to some similar threads?
6:39 pm on Feb 11, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


I would suggest that you forgo the use of mod_rewrite if this example is unclear to you; It is dangerous to copy-and-paste code into your server configuration that you do not fully understand.

RewriteCond 00>%{QUERY_STRING} ^(00)>id=([0-9])$ [OR]
RewriteCond 0>%{QUERY_STRING} ^(0)>id=([0-9]{2})$
RewriteRule ^new\.php$ http://www.example.com/new.php?id=%1%2 [R=301,L]

Note that this code will not work if additional query string parameters precede or follow "id=" -- It will need to be made quite a bit more complex to handle that situation.

Jim
7:11 pm on Feb 11, 2010 (gmt 0)

New User

5+ Year Member

joined:Feb 10, 2010
posts:20
votes: 0


Thank you very much jdMorgan, you really helped me.
It works like a charm.
And whoo, I understand it :)
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members