views:

9

answers:

1

Hi

I'd like to redirect: http://site.com/FOO/BAR/BAZ

to http://site.com/FOO/NEW/BAZ

so, subsitute the second segment in my URL with a new one.

ideally I'd like to use HTACCESS and a 301 as these pages have permanently moved.

The URL structure will not change. Ideally there won't be a query string, but doesn't matter too much is there is.

thanks

8EDIT* - I should clarify and say that "BAR" is not a wildcard - it is one word. the real life example is:

old Links: site.com/events/details/XXX

new links: site.com/events/VIEW/xxx

I don't want: site.com/events/add-new

to redirect. JUST if the second segment equals "details" in my case.

further clarification sorry haven't been exactly clear.

Existing URL: site.com/events/details/%wildcard%

should redirect to site.com/foo/view/%wildcard%

but nothing else.

+1  A: 

What about this one?

RewriteEngine On
RewriteRule ^FOO/(.+)/BAZ$ FOO/NEW/BAZ [L,R=301]

EDIT: Not sure, but you may need to pass the whole address, here's another sample of code:

RewriteEngine On
RewriteRule ^FOO/(.+)/BAZ$ http://site.com/FOO/NEW/BAZ [L,R=301]

2nd edit: Here's the final solution. I've tried it today on a shared hosting and it worked well.

RewriteEngine On
RewriteRule ^FOO/(.+)/BAZ$ http://site.com/FOO/NEW/BAZ/ [L,R=301]

The only difference is that the last example contains a slash (/) at the end of the new path.

rhino
thanks, will test it now. I have slightly amended my post as well.
Ross
not quite working, but +1 for the help anyway
Ross
musta been the slash, this htaccess stuff boggles my mind. much obliged
Ross