user962876
user962876

Reputation: 31

.htaccess Redirect sub-folder

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.

Upvotes: 3

Views: 1173

Answers (2)

blad
blad

Reputation: 664

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...

Upvotes: 0

Book Of Zeus
Book Of Zeus

Reputation: 49867

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]

Upvotes: 6

Related Questions