Redirect 301 with regular expresions to other url with similar numeration

我的梦境 提交于 2021-01-05 08:58:19

问题


I migrated my articles in website, and the CMS system transform de URLs.

I need to redirect URLs similar to:

Example, Case 1. Same article name and diferent number at the end of URL:

Original URL: https://www.website.com/folder/2087-name-of-the-article

Source URL https://www.website.com/folder/name-of-the-article-r929/

Example, Case 2. Same article name and diferent number at the end of URL, but with other subfolder:

Original URL: https://www.website.com/folder/2087-name-of-the-article

Source URL https://www.website.com/folder0/folder/name-of-the-article-r929/

Many Thanks and Marry Christmas.


回答1:


Could you please try following, written and tested with shown samples. Please make sure you clear your browser cache before testing your URLs. In case you want to redirect(change URL in browser too) then add R=301 with L flag in both the rules.

RewriteEngine ON
RewriteRule ^folder/name-of-the-article-r929/?$ folder/2087-name-of-the-article [L]
RewriteRule ^folder0/folder/name-of-the-article-r929/?$ folder/2087-name-of-the-article [L]

This considers you want to rewrite http://localhost:80/folder/name-of-the-article-r929/ to http://localhost:80/folder/2087-name-of-the-article

AND http://localhost:80/folder0/folder/name-of-the-article-r929/ TO http://localhost:80/folder/2087-name-of-the-article.

Where localhost could be your domain name.



来源:https://stackoverflow.com/questions/65499517/redirect-301-with-regular-expresions-to-other-url-with-similar-numeration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!