4

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.

Ross
  • 18,117
  • 7
  • 44
  • 64
  • Please check the second edit in my answer. This one should work for you, I've tried it. – rhino Oct 22 '10 at 12:08

1 Answers1

4

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
  • 13,543
  • 9
  • 37
  • 39