I’m trying to redirect this kind of URL:
kod-rabatowy/groupon/1234
kod-rabatowy/groupon/12345
To:
kod-rabatowy/groupon/
“groupon” is a variable that I want to have in new url.
So only when it ends with 4 to 5 numbers – the new one ignores the value after 2nd slash.
I tried that but I doesn’t work:
RewriteCond %{REQUEST_URI} ^kod-rabatowy/(/.*|)/([0-9]{4,5})
RewriteRule ^kod-rabatowy/([^/]+)/([^/]+)$ kod-rabatowy/$1 [R=302,L,NC]
Do you know how to fix it? I’m new to this.
Miłosz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6
%{REQUEST_URI}
always starts with a slash, so your RewriteCond pattern did not match here. But you don’t really need to use a RewriteCond to begin with, when you only need to match on the path component of the URL – the RewriteRule can do that on its own.
RewriteRule ^kod-rabatowy/([^/]+)/[0-9]{4,5}$ kod-rabatowy/$1/ [R=302,L,NC]
should do the trick for what you want here.