I need help writing an htaccess redirect or rewrite rule (mod_rewrite.c) to handle the following situation:
http://www.mysite.com/archive/[YEAR]/archive/[YEAR]/[CORRECT-PATH]
should redirect to:
http://www.mysite.com/archive/[YEAR]/[PATH]
Basically, there are some externals links that have incorrectly doubled-up on the /archive/[YEAR]/ part of the path, where there should only be one instance. I have a sub-directory for each year (/archive/2011, /archive/2012, etc.) – those year directories are the roots of separate Drupal installations – each with their own .htaccess file (which is tripping me up).
The [CORRECT-PATH] bit is usually an alias to a Drupal page, for example:
http://www.mysite.com/archive/2012/winners/all
I’m not so good with wildcard and matching syntaxes – any help would be appreciated. Thanks.
Try adding these rules to your document root:
This checks that the year is duplicated, for any 4 digit year. so:
http://www.mysite.com/archive/1234/archive/2345/blah/blahdoes nothinghttp://www.mysite.com/archive/2345/archive/2345/blah/blahgets redirected tohttp://www.mysite.com/archive/2345/blah/blahhttp://www.mysite.com/archive/1234/blah/blahdoes nothing.After looking at your problem again, you’re going to need to add rules to each of your
/archive/[YEAR]directories:And change the
RewriteBasefor each of your directories.