thecadams / 301RedirectModule

An improved version of the Sitecore 301 redirect module by Chris Castle, available at http://trac.sitecore.net/301RedirectModule
MIT License
30 stars 67 forks source link

Issue while preserving the query strings #25

Open dkchittimilla opened 7 years ago

dkchittimilla commented 7 years ago

We have a requirement for redirecting the old site URLs to new site as per the information architecture in sitecore.

In the existing site we have URLs in below format

http://site.com/solutions?sid=1001

In this URL will be same and sid will be changing.

As per the information architecture in new site, we have an item for each sid. So we can access the above page in new site using below URL.

http://site.com/solutions/1001

Currently we have around 100 of these kind of pages and we are planning to write a regular expression for doing URL redirection. We already installed 301 redirect module available in market place. Can you please suggest us the proper regular expression which satisfy this requirement.

I am trying to use the below, but it is not working properly. Source: ^\?sid=(\w+)* Target: /sitecore/content/MySite/Home/solutions/$1

thecadams commented 7 years ago

The ^ means "match the beginning of the string". Is that what you wanted? You might want to try removing it.

dkchittimilla commented 7 years ago

Thanks for the update. I just changed my source expression and now the updated one look like below.

Source: ?sid=(\w+)* Target: /sitecore/content/MySite/Home/solutions/$1

But still when I browse http://site.com/solutions?sid=1001 it is staying on same page rather than redirecting to http://site.com/solutions/1001

Is my target expression correct?

thecadams commented 7 years ago

Looks like you need to escape the "?", too. I recommend using a regex tester such as this one: http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx

Hope that helps - and thanks so much for using the redirect module! Myself and everyone who's worked on it really appreciate it!

dkchittimilla commented 7 years ago

I removed that but still facing same issue. Can you correct my target expression. I am using $1 in that. Is that correct way to retrieve parameters. I tried in the regex tester tool (link you provided) and it is giving one match.

Your help is really appreciated.

thecadams commented 7 years ago

It is a valid approach, can't see anything that should stop that from working!

Perhaps the path and query are operated on separately.. are you able to use the backreference to replace a portion of the path only (eg. /solutions/sid-1001 to /solutions/1001)? And are you able to use it to replace part of the query string (eg. /solutions?sid=1001 to /solutions?value=1001)?

I also wonder if maybe the Target field needs to refer to a valid Item path, or else it might need to contain the desired URL.