Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 984
user962876 Avatar asked Feb 13 '26 20:02

user962876


1 Answers

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]
like image 191
Book Of Zeus Avatar answered Feb 17 '26 03:02

Book Of Zeus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!