问题
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