Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess redirect pattern not working

I am using the following code in my htaccess file

Redirect 301 /([0-9]{1,2})+_([A-Za-z])$ /brand/$1-$2

to redirect the following type of URL pattern :

www.mywebsite.com/{ID}_{BrandName}

So basically I have to redirect

www.mywebsite.com/{ID}_{BrandName} to www.mywebsite.com/brand/{ID}-{BrandName}.

For example : Redirect 301 to www.mywebsite.com/5_TestBrand to www.mywebsite.com/brand/5-TestBrand.

Please suggest.

Below is the htaccess code which is not working :

Redirect 301 /([0-9]{1,2})+_([A-Za-z])$ /brand/$1-$2

Please Guide.

Thanks !

like image 442
vanurag Avatar asked Mar 08 '26 03:03

vanurag


1 Answers

You cannot use regex and captured groups in Redirect directive. Use RediectMatch instead:

RedirectMatch 301 ^/([0-9]+)_([A-Za-z]+)/?$ /brand/$1-$2
like image 165
anubhava Avatar answered Mar 09 '26 15:03

anubhava