2

I would like to have to following rewrite rule:

  1. The query string must begin with choice1 or choice2
  2. The query string contains only one other value
  3. The domain should be path of the final url
  4. The final url should not contain the query string.
  5. The final url should contain the two values of the query string in its path

I have this so far (with help from here):

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(choice1|choice2)&([^&.]+) [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?([^\.]+)\..+$ [NC]
RewriteRule ^ https://www.mysite.de/link/%1/%2/%3 [L,NE,R=302]

The conditions work fine. But the final url does not contain the values of the query string (%1 and %2). Also the query string is appended, although I do not use the QSA-Flag.

Some examples:

first-domain.de?choice1&abc => https://www.mysite.de/link/choice1/abc/first-domain
first-domain.de?choice2&xyz => https://www.mysite.de/link/choice2/xyz/first-domain
second-domain.de?choice1&ttt => https://www.mysite.de/link/choice1/ttt/second-domain
second-domain.de?choice2&xyz => https://www.mysite.de/link/choice2/xyz/second-domain
1
  • Can you please add some examples of source and target URLs Commented Jun 19, 2020 at 19:16

1 Answer 1

2

You may use this rule:

RewriteEngine On

RewriteCond %{QUERY_STRING}#%{HTTP_HOST} ^(choice1|choice2)&([^&#]+)#(?:www\.)?([^.]+)\. [NC]
RewriteRule ^ https://www.mysite.de/link/%1/%2/%3? [L,NE,R=302]

Reason of using %{QUERY_STRING}#%{HTTP_HOST} in a single condition is that we can only use most recent RewriteCond for capturing values %1, %2, %3 etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.