简体   繁体   English

使用.htaccess将类别及其所有发布重定向到新的URL

[英]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. 我想将一个类别的所有URL重定向到新域。

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. 例如,test.saptraininghub.com / sap-basis-training-tutorials / how-to-lockunlock-a-user-2到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. 想要将test.saptraininghub.com/sap-basis-training-tutorials重定向到joomla5.guru99.com/sap-basis-training-tutorials.html。

I have wrote following directives in .htaccess 我在.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. 它实际上是重定向的,但不是正确的URL,而是在浏览器的地址栏中找到以下URL。

' http://joomla5.guru99.com/sap-basis-training-tutorials.htmlhow-to-lockunlock-a-user-2 ' ' 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而不是Redirect

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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