Routing aspx file

Topics: Customizing Orchard, General, Troubleshooting
Jan 9, 2013 at 11:06 PM
Edited Jan 9, 2013 at 11:12 PM

I've got a site up and running nicely with Orchard (migrating from an old site in php).

The problem I've got now is that there are a lot of pages indexed in google against the old php site (with the old domain name).

The plan is to switch the old domain over via DNS to the new domain name and the Orchard site.

An old link in google is similar to www.olddomain.com/products/all/make/condition/Partno.html

(Ideally I'd like this to go to a URL like www.newdomain.com/products/all/index.aspx?p=partno&m=make&c=condition)

In reality this maps to a php file called index in the products/all directory - this takes the parameters make, condition and part no to do its processing (it doesn't point to a physical file)

I need to replicate this functionality in the Orchard site (so any requests coming in will get taken to an appropriate page).

At present, as there nothing in place to handle this on the orchard site, so I'm just getting a this page cannot be found as the content of the orchard page.

What would be the best way for me to handle this?

I've thought of putting a web form into the all directory and then manipulating the request to get the parameters out (not 100% sure how to make the aspx become extension less though). I've tried this and it seems to work, other than not being able to remove the aspx extension from the URL, which isn't much use for me at the moment (havn't got to the parameter part yet)

Another option I've thought of is to use the URL rewrite option in iis7, but not sure if this will give me what I want, yet alone know what rule to setup to do this.

Or, should I create a custom module called products, with a controller action of all to handle the request and get this to mimic the original php file?

Not sure which way to go with this. Anyone got any suggestions on he best route for me to try?

Coordinator
Jan 10, 2013 at 1:16 AM

URL rewrite is 100% the right thing to do here. Do configure it with permanent redirects.

Jan 10, 2013 at 9:29 AM

Thanks for that - saved me some time going down the wrong road :)

Just managed to crack it - wasn't as bad as I thought it would be - here's the rewrite section of the web.config (in case it helps someone else do something similar in future):

       <rewrite>
            <rewriteMaps>
                <rewriteMap name="/products/all/.*" />
            </rewriteMaps>
            <rules>
                <rule name="Products Mapping" stopProcessing="true">
                    <match url="^products/all/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)" />
                   <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                   </conditions>
             <action type="Redirect" url="/products/all.aspx?m={R:1}&c={R:2}&p={R:3}" />
                </rule>
            </rules>
        </rewrite>