Code Monkey home page Code Monkey logo

301redirectmodule's Introduction

301RedirectModule

An improved version of the Sitecore 301 redirect module. Original version was created by Chris Castle. Now upgraded and compatible with Sitecore 9.1 (version 1.7)

Improvements by Chris Adams, Max Slabyak, Mark Wiseman, Thomas Baek, and timgriff84

Changelog

Version 1.9:

  • Upgraded for compatibility with Sitecore v10.0 pravin
  • Install package re-created

Version 1.8:

  • Upgraded for compatibility with Sitecore v9.2 santosh
  • Install package re-created

Version 1.7:

  • Upgraded for compatibility with Sitecore v9.1 kaalen
  • Added security role modules\Redirect Module Admin. Add users to this role to allow them to configure redirects.
  • Install package re-created

Version 1.6.1:

  • Item names with dashes could break the regular expression redirect if EncodeNames is set to true on Sitecore Link Manager, this is a minor fix, - contributed by Mohammed Syam
  • Release zip files can no longer be provided due to challenges building the package - please build your own package or contact Chris Adams for support.

Version 1.6:

  • Fixed a bug int he delete command that is in the notification bar.
  • Added a rule based redirect

Version 1.5:

  • Added missing English language versions on template fields.
  • Complied against 8.2 dlls
  • Changed Target Framework Version to 4.6.1
  • Added Notifications to Content Editor
    • If an item is the target of redirects, you can see, manage, and delete them.
    • If the item is a redirect Url item, you can quickly navigate to the target.
  • Added a handler to automatically generate redirects as pages are moved. This is controlled by a setting in the config file.

Version 1.4:

  • Added the ability to select HTTP status code (301, 302)

Version 1.3:

  • Added support for redirects to a raw Url - contributed by Mark Wiseman

Version 1.2:

Version 1.1.2:

  • Fixed an exception when using exact URL matching on pattern items.

Version 1.1.1:

  • Support for encodeNames="true" (used for Sitecore friendly URLs; most notably, this will make redirects work when dashes in URLs correspond to spaces in item names)

Version 1.1:

  • Redirects for items which already exist
  • Case-insensitive URL matching
  • Path and query matching

New Features

  • Works with Sitecore friendly URLs!
  • Case-insensitive matching of URLs
  • Ability to process redirects for specific items which already exist. Useful if you have an existing item, but need to change part of a query string. Beware of the performance implications as the list of items is examined against every request.

Redirecting when items already exist

  • Match the path and query of a request, ignoring the hostname portion of the user's request. Useful if you need your match to work in multiple environments but don't want to list them in the redirect item.

Redirecting and modifying the query string

The regular expression above in the "Requested Expression" field will match any request where the path portion of the URL begins with /old-site-area. For instance, a request to http://mysite.com/old-site-area/homepage will be processed by this redirect. As a side-effect, the path portion under /old-site-area ("/homepage") will be saved for later in a capture group called Path. This is the "^/old-site-area(?/.*?)?" portion of the regular expression.

Because Sitecore accepts URLs ending with .aspx, this regular expression will also process a request to http://mysite.com/old-site-area/homepage.aspx. This is not compulsory but recommended, otherwise you have 2 URLs pointing to one page. This can cause search engines to penalise your content for being duplicated twice on your site. Removing the .aspx extension will help make your content look like it only lives in one place. This is the "(.aspx)?" portion of the regular expression.

Lastly this regular expression accepts (but does not require) a query string, so this regular expression will also match a request to http://mysite.com/old-site-area/homepage.aspx?thesky=blue. This is the "(??.*)?$" portion of the regular expression.

This looks complicated but it's not magic; it's just regular expressions. This is using .NET framework regular expression syntax. You can learn about regular expressions on Wikipedia and test a regular expression with Derek Slager's .NET Regular Expression tester.

OK, example time. A user just sent a request to http://mysite.com/old-site-area/homepage.aspx?thesky=blue. What happens?

  1. The "Requested Expression" is tested and found to be a match, as per above.
  2. The value of the "Source Item" field is substituted as needed. In this case, ${Path} will become "/homepage" and ${OptionalQueryString} will become "?thesky=blue", so the final value of "Source Item" for this request becomes "/sitecore/content/Site/New Site Area/homepage?thesky=blue". ${Path} and ${OptionalQueryString} are names you can see in the "Requested Expression" field.
  3. Everything before the question mark is used to look up the path of an item in the Sitecore tree.
  4. If an item is found, its friendly URL is retrieved. In this case, the URL will be http://mysite.com/new-site-area/homepage
  5. The query string is put on the end. In this case, the URL will become http://mysite.com/new-site-area/homepage?thesky=blue
  6. A 301 redirect is issued, which tells browsers and search engines that the URL the user requested (http://mysite.com/old-site-area/homepage.aspx?thesky=blue) can now be found at http://mysite.com/new-site-area/homepage?thesky=blue.
  7. The user's browser follows the redirect and requests http://mysite.com/new-site-area/homepage?thesky=blue.

Examples

Match only the path, dropping the query string
  • Requested Expression: ^/MovedItem/?
  • Source Item: /sitecore/content/MySiteRoot/Destination
Replace some of the query string but don't redirect away

Under the Content tab of /sitecore/System/Modules/Redirect Module, Edit the field Items Which Always Process Redirects and add an item, eg. /sitecore/content/MySiteRoot/SomeItem/Path

  • Requested Expression: ^/SomeItem/Path/?\?(.*)name=OldValue(.*)
  • Source Item: /sitecore/content/MySiteRoot/SomeItem/Path?$1name=NewValue$2
Improving SEO: Remove .aspx extension
  • Requested Expression: ^/MovedItem(.aspx)?$
  • Source Item: /sitecore/content/MySiteRoot/Destination
Preserving the query string
  • Requested Expression: ^/MovedItem(?<OptionalQueryString>\?.*)?$
  • Source Item: /sitecore/Content/MySiteRoot/Destination${OptionalQueryString}
Move an area of your site
  • Requested Expression: ^/MovedSiteArea(?<Path>/.*?)?(.aspx)?(?<OptionalQueryString>\?.*)?$
  • Source Item: /sitecore/content/MySiteRoot/NewLocationOfSiteArea${Path}${OptionalQueryString}

Other goodies

How to redirect other extensions

With thanks to RyanEaves, https://github.com/RyanEaves - originally from #3

I needed to use this to migrate from a PHP based site, and it took some work to figure out how. So I thought I would share the knowledge. These instructions are for IIS6, although I'm sure you can derive how to do it in IIS7 easily.

  1. Add the extension mapping in IIS for your site.

    Go to properties for your site, Home Directory, Configuration button, Mappings tab, Add...

    • Executable: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

      Note: The above path will be different for you if you use x64 or a different version of .net. Just use the same path that is mapped to the .aspx extension and it will work.

    • Extension: .php

    • All Verbs

    • Script engine: checked

    • Verify that file exists: UNCHECKED (very important)

    Click OK

  2. Tell Sitecore to process php files:

    • Open Web.config
    • Do a search for: Sitecore.Pipelines.PreProcessRequest.FilterUrlExtensions
    • Underneath that line, there is a parameter for "Allowed extensions". Add php to the list.

DONE! Now you can add rules to this module that redirect .php files.

You can do this exact same process for other extension types like .html, .jpg/.gif/.png, .pdf, etc as well if you need to redirect those.

Hope that saves someone a few hours of research!

301redirectmodule's People

Contributors

alenpelin avatar bhanunexus avatar chris-castle avatar dru-ward avatar estockwell-alpert avatar himynameistim avatar joshka avatar kaalen avatar leloo1982 avatar markgibbons25 avatar markotsoi avatar mawiseman avatar maxslabyak avatar mdownermindstream avatar mohamed-syam avatar poojarsn avatar pravinpagarebupa avatar thecadams avatar thomasbaek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

301redirectmodule's Issues

Time period

Hello,

I am testing your module for a customer and it works great. My only question is do you intend of adding a time period per redirect rule. For example some redirects to work for a month or so and after that to be disabled automatically.

Thank you

In Azure there is a thread-problem with rules

We used rules for a while and it worked well. Now we moved with our project into the cloud and we encountered problems with rules. It seems that they are not thread safe. It's a tricky problem, because it only happens on production, where we have a lot of concurrent threads in different languages.

Is it already a known bug? Maybe it is a problem with Sitecore rules engine.

Redirect Pattern to new URL

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

Sitecore 9 Compatability

Hello,

Is this module compatible in Sitecore 9? I tried to install the module and upon changing the RedirectModule.Config values for the settings (below) to true

I am getting an exception:

Exception information:
Exception type: MissingMethodException
Exception message: Method not found: 'Sitecore.Links.LinkProvider Sitecore.Links.LinkManager.get_Provider()'.
at SharedSource.RedirectModule.Processors.RedirectProcessor.CheckForRegExMatch(Database db, String requestedUrl, String requestedPathAndQuery, HttpRequestArgs args)
at SharedSource.RedirectModule.Processors.RedirectProcessor.Process(HttpRequestArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
at Sitecore.Web.RequestEventsHandler.OnPostAuthenticateRequest(HttpContextBase context)
at Sitecore.Nexus.Web.HttpModule.��(Object ��, EventArgs ��)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Is there something else that I need to configure?

redirects in a multisite solution

Hello,
I am testing your module for a customer right now with a multisite solution. And I wanted to know if there is a way to enable redirects only for a specific site-config.
The problem is if there are pages with the same names under different sites, your module will redirect both urls.

Redirect Rule

I presume that item of type Redirect Rule is not working as expected with Sitecore 8.2 update 2

Is it working for anyone else?

Issue while preserving the query strings

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

How to use with 6.5

I've uploaded the module and see it in my system folder. The templates are there, but where do i actually insert the template to redirect from one URL to another? I tried it in the product page and it didn't work. I am trying to redirect a page-product

Redirect pattern not working with a bucket item

Hello, i'm having a problem with the redirect pattern item.

This is my setup:
Requested Expression: ^/assets/files/news/press_releases/.*\.pdf
Response Status Code: 301
Source Item: /sitecore/content/Home/News and Community/Press-Releases

The goal: all pdf's under /assets/files/news/press_releases/.../*.pdf are deleted so i'm redirecting all those to the route /News and Community/Press-Releases
The problem: the pdf's url's are giving 404 instead the redirection. i.e.: http://local.mysite.com/assets/files/news/press_releases/2016_PR/Custom-Release.pdf

Some information:

  • The /sitecore/content/Home/News and Community/Press-Releases is a bucket
  • if i point the Source Item to News and Community the redirect works
  • if if enter on the address bar http://local.mysite.com/news-and-community/Press-Releases it works perfectly.
  • The .pdf extension is included on Sitecore.config allowed extensions.

So.. what's going on? do i have something wrong?

Redirecting old asp page to New aspx

i am using this module , it is working fine untill i am using different oldpage name and new page name.
As soon as i have same new page having old page name it is not working.
/contact.asp to /home/contact.aspx
Not working.

I have asp as allowed extension.

without entering asp as allowed Language it is not working, it redirects to 404 page

Any Help or i am doing something wrong.

Where is the install package?

This seems like a really dumb question but I can't find the installation package for this module. There's nothing under releases and I don't see it in the repo

Install package 1.7 missing items

The install package is missing a few things that are in the source/serialisation.

  • Modules Sitecore Domain
  • Redirect Rules Definition Elements
  • Redirect Rules Definition Tags

Causing Delay for custom APIs

Hello, love the module, I just have a little issue...

The site I administer is over 3 years old and is constantly updated, as a consequence the Auto Generated URLs have accumulated over time into the many thousands, 7300 in fact. This became an issue because calls to extremely simple APIs were taking 2-3 seconds to respond.

It is definitely the Redirect Module causing the delay because I can see the time taken in Sitecores Admin Pipeline profiler. Also because the test web service is minimal code returning 'hello world'.

I of course deleted all the redirects the customer considered unnecessary, the remaining 700 redirects still have a delay of 1.2sec, this is (sort of) acceptable as a one time delay to load the webpage but its a big problem as a delay on web services, of which the site has many.

Is there some way to stop the redirects being triggered on Customer URLs? I tried patching my custom config to initialize the process before the redirect module but this had no effect on the delay. I can change the code myself but I would prefer an official answer to prevent accidental future overwrites.

Thanks!

Sitecore 9 support

The module does not officially support Sitecore 9 as per its marketplace page:
https://marketplace.sitecore.net/Modules/301_Redirect_module.aspx

When installing module to Sitecore 9, it leads to following exception in various part of Sitecore Client user interface:

[MissingMethodException: Method not found: 'Sitecore.Links.LinkProvider Sitecore.Links.LinkManager.get_Provider()'.]
   SharedSource.RedirectModule.Processors.RedirectProcessor.CheckForRegExMatch(Database db, String requestedUrl, String requestedPathAndQuery, HttpRequestArgs args) +0
   SharedSource.RedirectModule.Processors.RedirectProcessor.Process(HttpRequestArgs args) +523
   (Object , Object[] ) +74
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +469
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
   Sitecore.Web.RequestEventsHandler.OnPostAuthenticateRequest(HttpContextBase context) +214
   Sitecore.Nexus.Web.HttpModule.��(Object ��, EventArgs ��) +335
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +139
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +88
--



Sitecore 9 - Allow Redirects On Found Item And Language Fallback

I believe there is an issue with the code in the RedirectProcessor in the method AllowRedirectsOnFoundItem when you are using Language Fallback.

There is the following line in the method:
var redirectFolderRoot = db.SelectSingleItem(redirectRoot);

It appears that using the SelectSingleItem() method does not seem to adequately support language fallback of the root folder item.

I changed this line to use the db.GetItem() method and this appears to properly support language fallback of the root folder item.

Redirect Rule not working on domain names - Sitecore.NET 8.1

Sitecore.NET 8.1 (rev. 160519)

I am trying to set up a redirect rule to redirect every page from one url to another url with the same sub-page pathing.

EX:
Rule 1
where the URL contains https://websiteexample.com
replace the static https://websiteexample.com with the static https://differentwebsite.com

Response Status Code [standard value]: 301 Moved Permanently

I want it to function so no matter what sub-page I am on, the redirect still works.

EX:
input domain: https://websiteexample.com/AboutUs.aspx
redirects to: https://differentwebsite.com/AboutUs.aspx

This currently does not function.

Where's the source?

I cannot find the source for this, just the compiled assemblies in the data folder?

Does this work in Sitecore 8.1?

Hi,

I tried installing this package using the Sitecore Installation wizard in Sitecore desktop but cannot see the redirect module within the System/Modules folder. Am i missing anything?

Thanks in advance,

Dashes in source item breaking redirect

We are using the Redirect module heavily for URLs, but are expanding to the Pattern redirects due to social media links. We are using them to make "short links" like site.org/HotLink. We are seeing the redirect fail if the Source Item has a dash. Wondering if anyone has seen this?

WORKS: /sitecore/content/MySiteRoot/DestinationOne
WORKS: /sitecore/content/MySiteRoot/Destination One
FAILS: /sitecore/content/MySiteRoot/Destination-One

Our pattern is pretty simple: ^(.)site.org/hotlink(.)$

Moving items in siteroot causes wrong requested Url

When moving a item in the siteroot, the redirect module create a autogenrated redirect, but the requested Url is wrong.

Example:
Siteroot/Testmove is moved to Siteroot/child/testmove
The requested url is set to: //testmove

I believe it is because of this line in AutoCreateRedirectOnMove.cs. Getting the path to the oldParent when the parent is siteroot will result in a / as the url:
string oldPath = LinkManager.GetItemUrl(oldParent).Replace("/sitecore/shell", "") + "/" + LinkManager.GetItemUrl(item).Split('/').Last();

When added another / before the items new url with result in "//".

I have resolved this by modifying this a bit:

var parentPath = LinkManager.GetItemUrl(oldParent).Replace("/sitecore/shell", ""); if (!parentPath.Equals("/") && parentPath.Length > 0) parentPath += "/"; string oldPath = parentPath + LinkManager.GetItemUrl(item).Split('/').Last();

License

Hi!

Thanks for your work on this project. It was easy to get up and running.

I'm interested in deploying this for my client, but I'm not altogether clear on what the license is. Could you add a LICENSE file or point out which, if any, license this is released under? Gotta make sure the lawyers are satisfied 😉

Thank you!

I got this working in 8.1 but had to add a english version

Hey, this works fine in 8.1 for me one issue i had though was that the field Response Status Code in the template redirect base didnt have an english version.
That meant it didnt publish the field to web and the app threw an exception when trying to get it (the if/else doesnt check for null first, probably worth adding)
Adding the english version of the field and republishing fixed the issue.
Only other things that may have helped is i rebuild with the 8.1 kernel and the .net app framework 4.5.2.

Andy

Doesn't work on sitecore 9

Hi,

I installed this module on sitecore 9 successfully with no errors. However, it doesn't work. I tried Redirect Url and Redirect Pattern Sample, and none of the worked.

I was wondering i you could let me know what I am missing.

Thanks

Support Coremedia 10 - Version 2001.1/2001.2

hi,

not really an issue but just a question regarding cm 10 support. is it planned for near future? and if so, can u tell a potential release date? otherwise we'll fork it and maybe can contribute the working version.

kind regards

I can't make it work with existing pages redirecting to another page

Hello, i'm trying to redirect an existing page (Url Redirect item) to another existent page and it doesn't work at all.

The configuration is:
Requested Url: /Careers
Response Status Code: 301
Redirect To Item: /MyNewCareers

The /Careers item exists
The /MyNewCareers item exists

if i go to my site root /Careers it goes to /Careers and no to /MyNewCareers
if i change the Requested Url setting to /testing (item doesn't exists), then if i go to my site root /testing, the redirect works and it goes to /MyNewCareers

Why this is happening? do i miss something?

Site level redirects

Considering an example below:

www.example.com/policy - redirect to global policy
www.example.ca/policy - redirect to policy page of Cannada only

As of now, redirects are global to all sites running in a sitecore node.
In multisite solution, it will be great if redirects are specific to a single site. We can fall back to global if needed.

Please see master branch created by me, let me know your thoughts on this.

Note: Feature Branch is not code complete.

Wanted to know team taught before I complete it and send a pull request.

302 redirection code

Hello,
I wonder if it would be possible to add a textfield for httpcode which would put codes 302 or 301. You could set the default value to 301.

Redirect Url items and Langauges

I was wondering if we can have the request url field unversioned
does that allow us use the same item for other langauges?
like
/welcome --> /en-us/weclomepage for the English version
/welcomen --> /de-du/welcomen for the Dutch version

Performance issue with RedirectProcessor.GetRedirects method

there are some 600+ redirect definitions created in Sitecore, it seems to fetch those redirects multiple times in pipeline processor, from our Dynatrace noticed that nearly 1sec is spent towards calling below method during request execution

public virtual IEnumerable<Item> GetRedirects(Database db, string templateName, string versionedTemplateName, string queryType)

is there a way we can optimize this?

Will this work on a development server?

Hi,

I'm attempting to test this on my development server, but it's not working. I was initially getting an error in the logs because I forgot to publish the templates, but now, the logs are clean yet it's still not redirecting when I use either option. I'm running Sitecore 6.6.

Documentation suggestion: How to redirect other extensions

I needed to use this to migrate from a PHP based site, and it took some work to figure out how. So I thought I would share the knowledge. These instructions are for IIS6, although I'm sure you can derive how to do it in IIS7 easily.

  1. Add the extension mapping in IIS for your site.

Go to properties for your site, Home Directory, Configuration button, Mappings tab, Add...

Executable: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll
Note: The above path will be different for you if you use x64 or a different version of .net. Just use the same path that is mapped to the .aspx extension and it will work.
Extension: .php
All Verbs
Script engine: checked
Verify that file exists: UNCHECKED (very important)
Click OK

  1. Tell Sitecore to process php files:

Open Web.config
Do a search for: Sitecore.Pipelines.PreProcessRequest.FilterUrlExtensions
Underneath that line, there is a parameter for "Allowed extensions". Add php to the list.

DONE! Now you can add rules to this module that redirect .php files. You can do this exact same process for other extension types like .html, .jpg/.gif/.png, .pdf, etc as well if you need to redirect those. Hope that saves someone a few hours of research!

Some fields only in French Canadian language and don't get published in version 8.1

I'm not sure if it being version 8.1 has anything to do with it, but a default install only has the English language.

/sitecore/templates/Redirect Module/Redirect Base/Information/Response Status Code doesn't have an English version and doesn't get published to the Web database, and then the code gives a YSOD when it can't find the Status Item.

Creating English language versions of the fields solved it for me.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.