Forum Moderators: phranque
http://www.example.com/cgi-bin/widgets/red-widgets.cgi
to
http://www.example.com/cgi-bin/widgets/pink-widgets.cgi
The cgi script generates a sub-directory (or two) and below that product pages, so I want to redirect everything below pink-widgets.cgi also, without changing any of their names.
Hope that all makes sense.
From my research here, I have come up with this:
RewriteRule ^red-widgets\.cgi/(.*)$ http://www.example.com/cgi-bin/widgets/pink-widgets.cgi/$1 [R=301,L]
1. Is there anything wrong with that?
2. Do I need the trailing / after .cgi? The reason I ask this is in the SERP's I have listings like
http://www.example.com/cgi-bin/widgets/pink-widgets.cgi
without the trailing slash for that particular directory. Of course for directories under that the / is included
http://www.example.com/cgi-bin/widgets/pink-widgets.cgi/smallpinkwidgets
So I guess my question is can I write the rule like this instead, removing the / after both .cgi?
RewriteRule ^red-widgets\.cgi(.*)$ http://www.example.com/cgi-bin/widgets/pink-widgets.cgi$1 [R=301,L]
TIA
edit for clarity
[edited by: StaceyJ at 8:19 pm (utc) on Oct. 3, 2007]
But the whole URL-architecture looks 'funny' to me. Why is that .cgi path-part in there in the first place? I'd be looking at using friendly URLs like
http://www.example.com/widgets/small-pink-widgets
and then internally rewriting them to the appropriate cgi script(s).
(This is beyond your current redirection considerations)
Jim
As for the .cgi being in the url, that is the next thing I've been wanting to fix - rewrite all the url's eliminating the /cgi-bin/ directory altogether along with the .cgi extension. But I wanted to get this done first and then move on and tackle that. I've read many a thread on that subject too.
But since it's an ecom site I'm somewhat hesitant to start now and take the chance of losing the rankings the site has until after the holidays are over.
...so, I should be safe with using
RewriteRule ^red-widgets\.cgi(.*)$ http://www.example.com/cgi-bin/widgets/pink-widgets.cgi$1 [R=301,L]
without the trailing / and have everything under pink-widgets.cgi still work properly?
Thanks again.
If you've read a lot of threads here, then you've seen that occasionally, something really odd prevents even trivial code from working as planned.
So, I tried it both ways, just for curiosity, with and without the slash. With the slash it re-wrote everything below the old red-widgets.cgi just fine, like
http://www.example.com/cgi-bin/widgets/pink-widgets.cgi/smallpinkwidgets
But it wouldn't rewrite just
http://www.example.com/cgi-bin/widgets/red-widgets.cgi
to pink-widgets.cgi
Removing the slash is what was indeed needed to rewrite that also.
Thanks again for your input, and all your informative posts.