7

All my WordPress post URLs generate sub directories with duplicate content and I do not know what regular expression to use to consistently 301 redirect domain.com/category/post/random-number/ to domain.com/category/post/ and domain.com/category/post/random-number/another-random-number/ also to domain.com/category/post/.

Here is an example of my problem:

  • http://www.example.com/features/harb-constitution-not-to-allow-kr-provinces-to-receive-foreign-officials/
  • http://www.example.com/features/harb-constitution-not-to-allow-kr-provinces-to-receive-foreign-officials/1345257927000/
  • 3
    Possibly the easiest solution here would be to use rel="canonical": support.google.com/webmasters/bin/… ; googlewebmastercentral.blogspot.co.uk/2009/02/… ; Redirect solution may also work (just generic regex), but since it will be generic regex, it may have false positives. The best solution therefore would be to redirect not at .htaccess level, but rather in actual PHP code, when proper URL is known for sure (compare actual URL to the expected one and if they differ redirect -- exactly the same approach used on this site). – LazyOne Sep 17 '12 at 14:58
2

First, I'd look at your URL settings (under "permalinks") to see why these URLs are being produced in the first place. I don't think they are by default. Ideally, you can just stop this from happening.

Second, is your site offering links to these unwanted duplicates? If so, I'd advise preventing that. If they're not linked to, users and search engines should never arrive at one.

0

If the urls always have a "real" folder depth of 2, this should work. It's basically saying "find pattern of any one or more characters that are NOT slash followed by slash, repeated twice". (.*) matches any chars that come after the 2nd slash (the random crap you want to throw away)

RewriteRule ^([^/]+/){2}(.*)$ http://www.example.com/$1 [R=301,NC,L]
0

I advise you to add your redirects via your control panel redirection section ( each control panel has this section for all types of domains) or just use .htaccess configurator via the link enter link description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.