Forum Moderators: phranque

Message Too Old, No Replies

rewrite and redirect changed directory name

         

StaceyJ

8:16 pm on Oct 3, 2007 (gmt 0)

10+ Year Member



Hi All. Been reading here for several years, but I seldom ever post so I seem to keep needing to re-register. Anyway, I have needed to rename a directory and I want to rewrite and 301 redirect users from

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]

jdMorgan

8:52 pm on Oct 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If pink-widgets.cgi is a script, then normally, no, it wouldn't have a trailing slash.

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

StaceyJ

9:11 pm on Oct 3, 2007 (gmt 0)

10+ Year Member



Thanks jd. I've read many upon many of your posts which is how I figured out what I did so easily, except for the slash, or no slash, part. I wasn't sure about that at all.

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.

jdMorgan

10:00 pm on Oct 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think so, but the only way to find out is to test. 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.

Understand about freezing the site until the holidays are over -- good plan.

Jim

StaceyJ

1:18 pm on Oct 4, 2007 (gmt 0)

10+ Year Member



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.

Yes, that's why I wanted to post what I had put together and make sure all looked good before testing. Testing something that's doomed not to work to begin with is something I try to avoid to save my brain cells. :)

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.