Forum Moderators: phranque

Message Too Old, No Replies

Help writing a htaccess redirect

         

realmaverick

8:35 pm on Dec 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey guys, I want to write a htaccess redirect.

from www.domain.com/widgets/ to www.domain.com/widgets/1-widgets/

But I don't want to effect anything else like /widgets/blue.html

Each time I do it, the other urls get effected.

Thanks a lot.

g1smd

9:42 pm on Dec 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Let's see some code!

You'll be using a RewriteRule.

Use example.com in this forum to prevent URL auto-linking.

[edited by: g1smd at 10:05 pm (utc) on Dec 7, 2011]

realmaverick

10:03 pm on Dec 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What code do you want to see? if it's my failed code, well it was a very basic redirect 301 /widgets/ to [domain.com...]

lucy24

11:02 pm on Dec 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, we want to see your failed code. The reaction will be either "We've seen worse" or "Yee haw, we have a new winner". But no code = no help ;)

Remember that you MUST use example.com. This is a generic WebmasterWorld Forums rule, but it is important for a whole separate reason in the Apache subforum. People have to be able to see what you typed.

When you say "/widgets/" do you mean "/widgets/ if not followed by any additional text"? Make sure you allow for the possibility of "/widgets/index.html" even if this file doesn't actually exist. You never know what will come up in someone's bookmark.

realmaverick

1:06 pm on Jan 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The exact code was:

Redirect 301 /widgets/ to http://www.example.com/widgets/1-widgets/

This works, but it also catches URL's such as /widgets/blue.html that I don't want it to.

I need it to be more specific I guess and only be that URL.

g1smd

8:01 pm on Jan 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use a RewriteRule instead of Redirect.

Add the $ end-anchor to the pattern so that it doesn't match those other requests.

Add the [R=301,L] flags.