[Solved] Custom Routes/Redirects/ContentFinder
c
Umb V13.3.2 Site has just gone live, now new SEO wants to do PPC all of a sudden. Site has a form that is called from many places and depending on 2 variables passed to it, cat & loc, decides what the form is for and where it goes. I built it to pass the arguments as either querystring or post. I thought I could get away using the Skybrud Redirects package by having the original URL as /mypage/builders/berkshire, and redirecting to /mypage/?cat=Builders&loc=Berkshire but it doesn't work. It doesn't even hit /mypage. If the redirect doesn't work, would a Content Finder approach be viable? I just don't want to go down the custom route route[sic] at this stage as it'd mean a major rewrite. Have I misunderstood how redirects work wrt querystrings? Any ideas appreciated.
s
Is your page using a controller method like Index(string cat, string loc)? Then you could add a [Route] attribute to it, like [Route("/action/etc/{cat}/{loc}")] and then decorate the paramters with [FromRoute] like Index([FromRoute]string cat, [FromRoute]string loc). Or the easy way - if you are using IIS. You can create a rewrite rule like:
Copy code
xml
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Rewrite builders and location" stopProcessing="true">
          <match url="^mypage/([^/]+)/([^/]+)$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/mypage/?cat={R:1}&loc={R:2}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
c
Thanks for that. Unfortunately not. Though I suspect it wouldn't be too much work just to add one just to be able to add the routing. The rest would just pass through. Hmmm, could ask the host about the IIS rewrite though. That might be easier.
Turns out we do have IISRewrite available, so got it working pretty easily. It was a bit more complex than my simplified test case, but it's working none the less. Thanks for the suggestions 🙂
18 Views