我有一堆需要重定向的 URL,并且 URL 中有 3 个主要模式
第一个模式
标题 url 开头有一个破折号-
,并且想要删除该破折号,例如
www.example.com/buzz/news/the-written--malice-of-rdicile www.example.com/buzz/news/the-written-malice-of-rdicile
www.example.com/break/news/5-kids--were-found-rigmaroling-armed www.example.com/break/news/5-kids-were-found-rigmaroling-armed
第二种模式
网址之间有两个破折号--
,需要更改为只有一个破折号-
,例如
www.example.com/buzz/news/-the-written-malice-of-rdicile www.example.com/buzz/news/the-written-malice-of-rdicile
www.example.com/break/news/-5-kids-were-found-rigmaroling-armed www.example.com/break/news/5-kids-were-found-rigmaroling-armed
第三种模式
标题 url 结尾有一个破折号-
,并且想要删除该破折号,例如
www.example.com/buzz/news/the-written-malice-of-rdicile- www.example.com/buzz/news/the-written-malice-of-rdicile
www.example.com/break/news/5-kids-were-found-rigmaroling-armed- www.example.com/break/news/5-kids-were-found-rigmaroling-armed
第四种模式 url 中存在起始破折号、双破折号和结束破折号的组合,并且想要删除起始破折号和结束破折号并将双破折号更改为单破折号,例如
www.example.com/buzz/news/-the-written--malice-of-rdicile- www.example.com/buzz/news/the-written-malice-of-rdicile
www.example.com/break/news/-5-kids-were-found--rigmaroling-armed- www.example.com/break/news/5-kids-were-found-rigmaroling-armed
www.example.com/break/news/-5-kids-were-found-rigmaroling-armed- www.example.com/break/news/5-kids-were-found-rigmaroling-armed
这些模式大约有 5000 行,因此寻找一种使用正则表达式或其他方法来运行所有 5000 行并将 apache 重写应用到 URL 的方法
非常感谢您的帮助。先感谢您
PS将继续编辑以使问题更清晰;任何问题?请问我。
总而言之,左边是要重定向的 URL,右边是用户需要访问的最终 URL
www.example.com/buzz/news/the-written--malice-of-rdicile www.example.com/buzz/news/the-written-malice-of-rdicile
www.example.com/break/news/5-kids--were-found-rigmaroling-armed www.example.com/break/news/5-kids-were-found-rigmaroling-armed
www.example.com/buzz/news/-the-written-malice-of-rdicile www.example.com/buzz/news/the-written-malice-of-rdicile
www.example.com/break/news/-5-kids-were-found-rigmaroling-armed www.example.com/break/news/5-kids-were-found-rigmaroling-armed
www.example.com/buzz/news/-the-written--malice-of-rdicile- www.example.com/buzz/news/the-written-malice-of-rdicile
www.example.com/break/news/-5-kids-were-found--rigmaroling-armed- www.example.com/break/news/5-kids-were-found-rigmaroling-armed
www.example.com/break/news/-5-kids-were-found-rigmaroling-armed- www.example.com/break/news/5-kids-were-found-rigmaroling-armed
答案1
最终我得到了匹配的源 URL 和目标 URL,并且不需要使用正则表达式来简化或进行任何优化。
所以只是逐行进行,所以 5000 行重定向..是的,我知道