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

Redirect Pattern to new URL #32

Open BenMurphyUK opened 7 years ago

BenMurphyUK commented 7 years ago

Hi,

I can't seem to get the module to redirect URL patterns to another URL. As I'm trying to redirect to a part of the site that is not in the CMS, I need to redirect to a new URL.

I've tried many combinations but can't seem to get it to work. Any help would be much appreciated.

Example: Requested Expression: ^/oldfolder/(.*)

Response Status Code: 301 Moved Permanently

Source Item: /newfolder/$1

thecadams commented 7 years ago

Hi! Having a little trouble understanding what you're having trouble with, but would really like to help.

Do you have a small site you can send over that reproduces the issue?

BenMurphyUK commented 7 years ago

I want to take an inbound URL rule (regex) and send it to another URL on the same domain.

E.g.

http://www.example.com/redirect

To

http://www.example.com/new/redirect

But also, the inbound rule needs to have a catch-all that will carry over anything at the end of the URL, hence the examples in my first post, using (.*) to $1.

Because the site I'm working on has a staging, QA, UAT, and live environments, using the full URL in the inbound rule isn't really viable as this changes per environment.

Hopefully that provides some more context.


Essentially, I need to get this rule into the CMS (taken from web.config):

<rule name="Arborfieldgreen to /developments/arborfield-green" stopProcessing="true">
    <match url="^arborfieldgreen(.*)" />
    <action type="Redirect" url="https://{HTTP_HOST}/developments/arborfield-green{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
thecadams commented 7 years ago

I wonder if it's the ^ in your Requested Expression? Pretty sure for regex replace items the entire URL is supplied, so it's not matching because it's supplied as https://www.example.com/oldfolder... which won't match..