locked
URL rewriting subdirectories to querystring RRS feed

  • Question

  • User-2143417194 posted

    Hello

    Let's say my website displays results for different restaurants in cities.

    Currently my website is:

    http://www.example.com/search.asp?city=Toronto&pr=Ontario
    http://www.example.com/search.asp?city=Winnipeg&pr=Manitoba

    city and pr(ovince) are passed to search.asp to display results.

    This works fine but for SEO purposes I'd like to change it.

    Ideally I'm looking to do this:

    http://www.example.com/Ontario/Toronto
    http://www.example.com/Manitoba/Winnipeg

    to rewrite to the above querystring.

    The issue is that people are able to add new cities at any time, which means that the rewrite shouldn't rely upon a pre-determined list of acceptable provinces or cities. Also I'm concerned that if I do use a rewrite, what happens if I happen to call a legitimate URL such as:

    http://www.example.com/users/photos/

    I wouldn't want that URL to be rewritten.

    I'm feeling my best (or only) option would be something like:

    http://www.example.com/places/Ontario/Toronto

    and have the rewrite look for "places"

    So far I've come up with: ^(.*/)www.example.com/search.asp\?city=([^=&]+)&(?:amp;)?pr=([^=&]+)$

    This however doesn't work. I have difficulty with the expressions that rewriting uses and could use some assistance please.

    Thank you in advance for any help.

    Saturday, March 7, 2020 1:00 AM

Answers

  • User-848649084 posted

    Hi,

    Is your issue solved?

    If your issue is solved then I request you to mark the helpful suggestion as an answer. This will help other people who face the same issue.

    If your issue still exists then try to refer the solution given by the community members.

    If then also you have any further questions then let us know about it.

    We will try to provide further suggestions to solve the issue.

    Thanks for your understanding.

    Regards

    Jalpa.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Wednesday, March 11, 2020 9:27 AM

All replies

  • User-848649084 posted

    Hi,

    You could try to use the below rule:

    <rule name="RedirectRURLE1" stopProcessing="true">
                        <match url="^search\.asp$" />
                        <conditions>
                            <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                            <add input="{QUERY_STRING}" pattern="^city=([^=&amp;]+)&amp;pr=([^=&amp;]+)$" />
                        </conditions>
                        <action type="Redirect" url="places/{C:1}/{C:2}" appendQueryString="false" />
                    </rule>
                    <rule name="RewriteRURLE1" stopProcessing="true">
                        <match url="^places/([^/]+)/([^/]+)/?$" />
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="search.asp?city={R:1}&amp;pr={R:2}" />
                    </rule>

    Regards,

    Jalpa

    Monday, March 9, 2020 3:29 AM
  • User-848649084 posted

    Hi,

    Is your issue solved?

    If your issue is solved then I request you to mark the helpful suggestion as an answer. This will help other people who face the same issue.

    If your issue still exists then try to refer the solution given by the community members.

    If then also you have any further questions then let us know about it.

    We will try to provide further suggestions to solve the issue.

    Thanks for your understanding.

    Regards

    Jalpa.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Wednesday, March 11, 2020 9:27 AM
  • User-2143417194 posted

    Hi Jalpa

    Thank you for the reply.

    It works! I will mark it as answered but I did run into an issue - which is why I never came back to check for replies. In playing with web.config I found that the queries with spaces in them (%20) failed.

    for example:

    /places/Mulmur%20Township/Ontario

    returns MulmurTownship

    The only solution it seems is to use hypens... such as Mulmur-Township. However then I'm left with search engines not capturing the proper name, the hypen appearing in the location title, etc.  I know I could do something like "Mulmur--Township" and use the replace command to put a space between the words but again as far as SEO goes, search engines would still see it as two words without a space.

    Sunday, March 15, 2020 2:42 AM