Developer forum

Forum » Development » Mapping old PageIDs to new IDs (DW8)

Mapping old PageIDs to new IDs (DW8)

Martin Nielsen
Reply
Hi Guys 

We have a customer that has moved from an old DW solution to a new DW solution (Fresh database).
On their old solution they shared it with a different brand, and therefore their page IDs startet at around 4000+.
Since they used the old URLs Google has indexed a lot of /Default.aspx?ID=4320 urls, and we want thise old mapped to their new corresponding pages.

Since DirectPaths isn't triggered when calling "/Default.aspc?ID=4320", we can't use that to do it. We don't have server access, so we can't do in on the IIS.

Which probably means that we have to create a custom module to handle this.

So i figured that i could create a notification that runs on PageLoad and check if the current ID is one of the old and then redirect to the new page, but i can't find a notification that fires when i hit the 404 page.

Is this true? Is there no subscriber for the 404 page?

Regards
 Martin

Replies

 
Pavel Volgarev
Reply
Hi Martin,

Unfortunately, there is no notification for that. What you could try is to specify a custom 404 handler under "HTTP 404" in your area settings. Set it to an internal page and write a notification subscriber (or custom module) that will trigger only for this page and make a redirect.

In a meanwhile I will create a work item for this (notifications from 404 handler).

-- Pavel
 
Morten Bengtson
Reply
Alternatively, you can add a rule in your web.config for each of the pages you want to redirect.

Redirect with IIS7
Place the following within the system.webServer section in web.config...
        <rewrite>
            <rules>
				<!-- add a rule for each redirect -->
                <rule name="redirect_old_page_4320" stopProcessing="true">
                    <match url="^Default\.aspx$" ignoreCase="true" />
                    <conditions>
						<!-- match the old page id (4320) -->
                        <add input="{QUERY_STRING}" pattern="^ID=4320(&amp;.*)*$" ignoreCase="true" />
                    </conditions>
					<!-- redirect to the new page id (123) - or a friendly url -->
                    <action type="Redirect" redirectType="Permanent" url="/Default.aspx?ID=123{C:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
The regular expressions used in the example may need to be modified slightly for your needs.

You should probably make sure that there will be no conflict with new pages, e.g. customer creates a new page that has same id as an old page.
To avoid this, you can change the identity seed on the PageID column in Page table to something higher than the old page ids.
 
Martin Nielsen
Reply
Thank you both for the ideas, I will try Pavel's suggestions first, since i planned on making this a reusable module for Dynamciweb.

Resorting to rewrite rules in web.config would make it hard for less geeky people to do it, but if it comes to it, i might have to go that way.
 
Martin Nielsen
Reply
Hi Pavel,

Do you know if it's possible to use Rewrite rules on your DW free/Express server?
AFAIK you requires a module installed on the IIS.

// Martin
 
Pavel Volgarev
Reply
Hi Martin,

URL rewrite module is not part of the IIS and should be installed separately (if you're asking about this).  If it's installed, it doesn't matter what version of Dynamicweb you're using.

-- Pavel
 
Martin Nielsen
Reply
 Hi Morten,

I've installed URL Rewrite on server, and created this rule.

<rewrite>
      <rules>
        <rule name="rule1" patternSyntax="ExactMatch" stopProcessing="true">
          <match url="Default.aspx?ID=1059" />
          <action type="Redirect" url="/priser-finansering/behandling-i-tide.aspx" redirectType="Permanent" />
        </rule>
      </rules>
</rewrite>
But when i access the url www.domain.com/Default.aspx?ID=1059  i get DWs standard 404 page.

Is it a problem that i want to redirect a URL when there's already a file of that name?

//Martin
 
Morten Bengtson
Reply
This post has been marked as an answer
Hi Martin,

Your rewrite rule is not triggered because the request does not match.

I'm pretty sure that you cannot match on query string values like you are trying to, because the match url is only checking the path of the request, e.g. "Default.aspx". You need to add a separate condition for QUERY_STRING.

Also, the url you specify on the match element is actually a regular expression pattern, so you need to escape characters that have special meaning in regular expressions, like . (dot).

Try this...
<rewrite>
	<rules>
		<rule name="rule1" stopProcessing="true">
			<match url="^Default\.aspx$" ignoreCase="true" />
			<conditions>
				<add input="{QUERY_STRING}" pattern="^ID=1059(&amp;.*)*$" ignoreCase="true" />
			</conditions>
			<action type="Redirect" redirectType="Permanent" url="/priser-finansering/behandling-i-tide.aspx" appendQueryString="false" />
		</rule>
	</rules>
</rewrite>

URL Rewrite Module Configuration Reference


Votes for this answer: 0
 
Martin Nielsen
Reply
 Hi Morten,

Thank you for the snippet. I tried it and it worked out great.

And thank god for Notepad++ and it's macros, changed all my wrong rules to the new format in 5 minuts :-)

// Martin 
 
Martin Nielsen
Reply
 Hi Pavel,

Did we ever get the notification for 404 pages?

// Martin
 
Pavel Volgarev
Reply
Hi Martin,

It's implemented as per #8563 ("Make it possible to receive notifications from 404 handler"). The new notification is Notifications.Standard.Page.NotFound and the corresponding event arguments type is Notifications.Standard.Page.NotFoundArgs.

This will be available in 8.2.

-- Pavel
 
Martin Nielsen
Reply
Great, looking forward to it :-)
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

FYI: I also added support for these notification to the Dynamicweb templates for Visual Studio. Should be out with version 1.7.1 and later.

 

Imar

 

 

You must be logged in to post in the forum