Creating redirects with parameter and different countriesRSS

1 reply

Last post Apr 22, 2020 02:06 AM by Jalpa Panchal

  • Creating redirects with parameter and different countries

    Apr 21, 2020 02:31 PM|JamieP1|LINK

    I have a website with the following URL structure

    www.example.com/usa/allproducts/product?pid=1
    www.example.com/ind/allproducts/product?pid=2
    www.example.com/uk/allproducts/product?pid=3
    www.example.com/ger/allproducts/product?pid=4

    I would like to have it so the URLs are friendly. Something like

    www.example.com/usa/allproducts/1/prod1Name
    www.example.com/ind/allproducts/2/prod2Name
    www.example.com/uk/allproducts/3/prod3Name
    www.example.com/ger/allproducts/4/prod4Name

    Within my code i can generate the friendly URLs but i cant get the rewrite rule. This is what i have

    <rewrite>
    <rules>
    <rule name="single product" patternSyntax="ExactMatch" stopProcessing="true">
    <match url="/usa/allproducts/product?id=$1" />
    <action type="Redirect" url="/usa/allproducts/.*/.*" appendQueryString="false" />
    </rule>
    </rules>
    </rewrite>

    This doesnt work so wondering how i could go about creating this? In addition i have a canonical rule and https redirect in place, for which i can provide the code for if required (not including this now as i didnt want to make the original code look messy)

    Thanks 

  • Re: Creating redirects with parameter and different countries

    Apr 22, 2020 02:06 AM|Jalpa Panchal|LINK

    Hi,

    You could try to use the below rule:

    <rule name="rule1" stopProcessing="true">
                        <match url="(.*)/allproducts/product$" />
                        <conditions>
                            <add input="{QUERY_STRING}" pattern="pid=(.*)" />
                        </conditions>
                        <action type="Redirect" url="http://www.sample2.com/{R:1}/allproducts/{C:1}" appendQueryString="false" />
                    </rule> 

    Regards,

    Jalpa

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.