Answer the question
In order to leave comments, you need to log in
.htaccess: How to use %N backreferences received in RewriteCond in other conditions?
Good afternoon!
I want to set it up so that every year all links with the old year are automatically redirected to the current year: https://site.com/folder/2020-february/ --->. https://site.com/folder/2021-february/
As done now:
RewriteCond %{REQUEST_URI} ^(.*)/2020(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)/2019(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)/2018(.*)$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%1/2021%2 [R=301,L]
#То есть каждый год приходится править условия
RewriteCond %{REQUEST_URI} ^(.*)/(2[0-9]{3})(.*)$
RewriteCond %{TIME_YEAR} >%2
RewriteRule ^(.*)$ https://%{HTTP_HOST}%1/%2%3 [R=301,L]
Answer the question
In order to leave comments, you need to log in
If there is a condition to check not strictly more, but simply a mismatch between %{TIME_YEAR} and %2
RewriteCond %{REQUEST_URI} ^(.*)/(2\d{3})(-.*)$
RewriteCond %{TIME_YEAR}_%2 !^(\d+)_\1$
RewriteRule ^ https://%{HTTP_HOST}%1/%{TIME_YEAR}%3 [R=301,L]
%{TIME_YEAR} -gt $2
RewriteCond expr "%{REQUEST_URI} =~ m#^(.*)/(2[0-9]{3})(-.*)$# && %{TIME_YEAR} -gt $2"
RewriteRule ^ https://%{HTTP_HOST}%1/%{TIME_YEAR}%3 [R=301,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question