We did some maintenance today, and moved our web forums from /forums into the root folder of the domain.
We put in a redirect 301 in a .htaccess file:
Redirect 301 /forums/ http://www.ourforums.com/
However, we used to have some links that contained duplicate /forums folders. I.e. www.ourforums.com/forums/forums/forum.1
Obviously the redirect from above now leads to /forum.1, which odes not exist. I would like the old link to actually point to www.ourforums.com/boards/forum.1. I attempted to use something like:
RewriteRule ^/forums/forums http://www.ourforums.com/boards/ [NC,R=301,L]
Regardless of what I tried though, the Redirect seems to supersede any RewriteRules I put in the same file, regardless of whether I place them before the Redirect.
Is there any way I can somehow ensure the RewriteRule is handled before the Redirect?
This is because mod_alias (the
Redirect
directive) and mod_rewrite (theRewriteRule
directive) is conflicting with each other in your case. Both of them play their part in the URL-file-mapping processing pipeline, where URI's get processed, rewritten, flagged, and eventually mapped to a resource and a response. You have aRedirect
rule which is getting applied and the response is being flagged as a redirect. The thing about theRedirect
directive is that it connects 2 path nodes together, meaning:is connected to
So anything below the
/forums
folder ends up getting redirected as well. This is why it's catching^/forums/forums
.You can either stick to just mod_rewrite or use a
RedirectMatch
that excludes/forums/forums
:or
Manually adding redirect statements like so seems to do the trick for me:
I had a somewhat similar problem. I was trying to add redirects from cpanel while I already had some rewrite rules written in my .htaccess file. The error I got was "No maching tag for " What I ultimately did was that kept a copy of my existing rules and cleaned the .htaccess. Then went and added all the redirects that I needed from cpanel, and then at the end put back my own rewrite rules in the end of the file. That worked for me