Welcome to WebmasterWorld Guest from 22.214.171.124
I've tried putting
Redirect /catalog [test.com...]
before and after the rewrite rules, but I get stuck in a loop.
Anyone know the correct way to do this?
Check out this thread for self-help: Introduction to mod_rewrite [webmasterworld.com]
If this doesn't help you, please give a few examples of the requested URL and what URL you want that request redirected to. Please include everything, including "http://mydomain.com" in both, just to be clear.
Also, do you use query strings?
I suspect your solution is an easy one, but as always, defining the problem thoroughly is the hard part.
OK, as I understand it, you wish to accomplish three things:
If so, this should work. The first two are external 301 redirects, and the last one is an internal redirect. That is important, and the order of the last two rules is also important to prevent a loop.
RewriteRule ^catalog http://www.site.com/ [R=301,L]
RewriteRule ^(cat¦dog¦cow)$ http://www.site.com/$1/ [R=301,L]
RewriteRule ^(cat¦dog¦cow)/(.*)$ /catalog/$1/$2 [L]
Remember to replace the broken vertical pipe "¦" characters with the solid ones from your keyboard.
> /catalog* are getting redirected to the root.
This redirect for /catalog is happening because of requirement number one, implemented in RewriteRule number 1. If the requirement is wrong, the Rule will be wrong, and it sounds like it is.
You can redirect anything that starts with catalog - including catalog followed by nothing, or anything that starts with catalog followed by a slash and anything else (including blank), or you can require that catalog/ be followed by another subdirectory and a slash - whatever you want. But the regular expressions used in mod_rewrite require that you be absolutely specific as to what you want rewritten and what you don't.
The redirects of cat¦dog¦cow may be taking place for the same reason - that the requirements are incorrect, so the Rule is incorrect. Or, they can be taking place because some down-stream .htaccess or script is doing another external (i.e. 301 or 302) redirect; In which case, the whole .htaccess file gets processed again. Take a look at your set-up and see if that might be the case. This could also be some weirdness in the server set-up (The SSI-include redirect thing sounds fishy to me).