Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect a category and all it's post to a new URL with .htaccess

I want to redirect all urls of a category to new domain.

For Example, test.saptraininghub.com/sap-basis-training-tutorials/how-to-lockunlock-a-user-2 to joomla5.guru99.com/how-to-lockunlock-a-user-2.html. I want to do this for all such urls

And,

want to redirect test.saptraininghub.com/sap-basis-training-tutorials to joomla5.guru99.com/sap-basis-training-tutorials.html.

I have wrote following directives in .htaccess

Redirect 301 /sap-basis-training-tutorials/ http://joomla5.guru99.com/sap-basis-training-tutorials.html
Redirect 301 /sap-basis-training-tutorials/how-to-lockunlock-a-user-2 http://joomla5.guru99.com/how-to-lockunlock-a-user-2.html

First one redirects fine but in later one, showing page not found error. It's actually redirecting but not at correct url and found following url in browser's address bar.

'http://joomla5.guru99.com/sap-basis-training-tutorials.htmlhow-to-lockunlock-a-user-2'

How can i solve this issue, Please assist me in right direction and help me to solve this.

Regards.

like image 960
Ram Guru99 Avatar asked Dec 05 '25 10:12

Ram Guru99


1 Answers

Use RedirectMatch instead of Redirect for regex capabilities:

RedirectMatch 301 ^/sap-basis-training-tutorials/(.+?)/?$ http://joomla5.guru99.com/$1.html

RedirectMatch 301 ^/(sap-basis-training-tutorials)/?$ http://joomla5.guru99.com/$1.html
like image 190
anubhava Avatar answered Dec 07 '25 23:12

anubhava



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!