简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM