0

Given the url: https://{SITE}/tgif/flink?search1=scode=atrre%20and%20year=2023&format=USGARS I want to rewrite it to https://{SITE}/tgif/flink/TERO/2023. Where 2023 is the only variable part of the redirect and format or search1 can come in either order.

My apache rewrite rules for this are:

 RewriteCond %{QUERY_STRING} (?:^|&)format=USGARS [NC] RewriteCond %{QUERY_STRING} (?:^|&)search1=scode(?:=|%3D)atrre(?:[\ +]|%20)and(?:[\ +]|%20)year(?:=|%3D)(\d{4}) [NC] RewriteRule ^tgif/flink$ /tgif/flink/TERO/%1 [QSD,R=301,L] 

The redirect does not work even though the regex validates using other tools, rather it is skipped as if it doesn't exist. I have dozens of other similar rewrites that work fine. The only difference I see in this is that this one has = signs in value for the search1 query. Does someone else see something wrong and/or know how to properly handle this instance? Does apache handle the extra = signs in some special way that I am not aware of?

2
  • The rule looks OK (although could be simplified). There is no special handling of = by Apache. More likely you have a conflict with your existing rules (or you are seeing a cached response). Please edit your question to include your complete .htaccess file with this rule in place. (Aside: You should test first with 302 - temporary - redirects to avoid caching issues.) Commented Aug 5, 2024 at 14:14
  • Aside: "I want to rewrite it to" - That's a "redirect", not a "rewrite". Commented Aug 5, 2024 at 14:18

1 Answer 1

0

I found my answer. The problem was actually in the RewriteRule line which should have been RewriteRule "^/tgif/flink" "/tgif/flink/TERO/%1" [QSD,R=301,L].

1
  • That would imply the rule is being used directly in the server (or virtualhost) config, as opposed to .htaccess or (<Directory> container) - which I had assumed earlier. (The original rule is correct if used in a directory context.) The double quotes are unnecessary here, but in removing the end-of-string anchor then you are matching /tgif/flink<anything> - is that necessary? Commented Aug 5, 2024 at 14:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.