3

Hi I'm not a programmer by any stretch of the imagination and am trying to do a multi 301 redirect in my htaccess file based on the following:

So I have a ton of urls all with similar naming conventions - here is a sample of 2.

http://www.hollandsbrook.com/garrett-at-gold/
http://www.hollandsbrook.com/garrett-ace-250/

These urls need to redirect to:

http://www.hollandsbrook.com/garrett-metal-detectors/garrett-at-gold/
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-ace-250/

I could just redirect them 1 line at a time, but I'd like to use regex.

Here's what I was thinking so far but not working:

RewriteRule ^garrett-([a-z])/$ /garrett-metal-detectors/$1/ [R]

Basically i need to redirect any page right off the root that starts with "garrett-" to include the folder path of "garrett-metal-detectors".

Any thoughts would be MUCH appreciated. Many thanks in advance for your help.

Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
user962876
  • 31
  • 3

2 Answers2

6

if you want temprorary redirect use:

RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=302,L]

if you want permanent redirect use:

RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=301,L]
Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
  • dude you rock! i realized i dont want to redirect the category page (garrett-metal-detectors) so I made a slight edit to your code: ewriteRule ^garrett\-([a-ln-z\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=301,L] Thanks again! – user962876 Sep 24 '11 at 19:03
0

I'm am not an expert on Regular Expressions, but looks like your reg ex may be a bit off...

try:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^((garrett)(-[a-z0-9]).*)/$ /metal-detectors/$1/ [R]

This is looking fro anything starting with "garrett" followed by any letter/number/hyphen combo.

Note: having "garett" in the destination part give you a loop of redirects, so you may have to choose a different word, or remove it all together...

blad
  • 665
  • 5
  • 8