Reputation: 3
I need help with a rewrite / redirect rule to fix some duplicate content issues on my website.
I have a URL structure that it causing a ton of duplicate content. The same page can be accessed with:
So, there are 3 copies of every page.
I need to redirect #1 & #2 from above to #3, so /Static1/Static2/Static3/{POSTID}/ is the only URL that will display the content, and the other 2 will 301 to it.
The post ID's and category ID's are only numbers but they can be a different number of digits ( /1/, /24/, /827/, etc.)
The titles include numbers, letters and dashes ( - )
/Static1/Static2/Static3/ represents the folder structure before the part I need to rewrite - those folder names are always the same, and should also be included in the URL.
Upvotes: 0
Views: 53
Reputation: 9007
It's really quite simple:
RewriteEngine On
RewriteRule ^(static1/static2/static3)/(\d+)/(\d+)(/[0-9a-z-]+)?/?$ /$1/$2 [NC,R=302,L]
The expression requires that the IDs be used, and makes the title and trailing slash optional.
To make the redirect permanent, change 302
to 301
.
Upvotes: 1