0

I'm adding some URL rewrite rules on my IIS so it redirects an old URL to a new location.

It works when the URL has only one query string parameter, but if I have more than one it does not work. Is there anything I can do so I can get the second parameter if it exists and if not just get the first one?

Here is my web.config rule.

<rule name="Rewrite rule1 for viewtopic.php" stopProcessing="true">
   <match url="^.*(?:viewtopic.php).*$.*" />
   <conditions>
     <add input="{QUERY_STRING}" pattern="^t=/name=([0-9]*)/" />
   </conditions>
   <action type="Redirect" url="https://example.com/view/{C:1}/topic" appendQueryString="false" redirectType="SeeOther" />
</rule>

The rule will work if my URL is like this. https://example.com/viewtopic.php?t=123456

Now I do have some old URLs that is formatted like this https://example.com/viewtopic.php?t=123456&highlight=Welcome

in this case when the IIS rule runs it gives me the following redirect URL https://example.com/view/123456&highlight=Welcome/topic and I'm trying to make the URL to be like this: https://example.com/view/123456/topic

1 Answer 1

1

According to your description, I suggest you could try to use below url rewrite rule.

It will only match the first query string value.

            <rule name="MultipleQueryStringRule" stopProcessing="true">
                <match url="^.*(?:viewtopic.php).*$.*" />
                <conditions>
                    <add input="{QUERY_STRING}" pattern="^t=([0-9a-zA-Z]*)" />
                </conditions>
                <action type="Redirect" url="https://example.com/view/{C:1}/topic" appendQueryString="false" />
            </rule>
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.