URL Rewrite and forwarding

John Sharp asked on August 7, 2015 13:44

Is there a way to prevent Kentico being helpful and redirecting my rewritten page URL?

I can use either URLRewrite or a custom module that listens for a URL and rewrites it correctly and am doing so, so for example, across the site I can have hundreds of URLs such as:

/a/b/c/d/e/f/g/h/?type=A&params=B
/a/b/c/d/e/f/g/?type=A&params=B
/a/b/c/d/e/f/?type=A&params=B
/a/b/c/d/e/?type=A&params=B
/a/b/c/d/?type=A&params=B
/a/b/c/?type=A&params=B
/a/b/?type=A&params=B
/a/?type=A&params=B
/?type=A&params=B

All of the URLs will eventually display the same page, /typeA/?param=B or /typeA/B/ (I haven't decided which to use yet). The problem is I still need access to the original URL /a/b/c/d/e/f for example and Kentico is forwarding the request from what I type in to the helpful Alias /typeA/ without the URL parts the user originally typed in.

What I really need is to find a setting that says "just display the page, don't re-forward the URL for SEO".

Recent Answers


Roman Hutnyk answered on August 7, 2015 14:28

Not sure I'm clear with the issue you have, but Settings -> URL and SEO -> Redirect pages to main extension - isn't it what you're looking for?

If it is not, I'd like you to answer following questions: Are those all URLs of the same page? Do you know why Kentico forwards user to another alias? Or this is what you are looking for? What you mean saying "don't re-forward the URL for SEO"?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 7, 2015 14:30

In Settings>URLs and SEO you can exclude URLs from being processed by Kentico. This would be my first place to make a chance.

Why not take advantage of Kentico's Wildcard URL ability to give you a more friendly URL by entering URL Aliases on that one page which will have all of these URLs? For example you have /A/B/?type=a&params=b. On the physical page in the content tree /A/B you go to Properties>URLs and add an alias like so /A/B/{type}/{params}. You'd do this for each URL you want or believe is possible to be accessed. So it could be /A/B/C/{type]/{params}. Kentico will rewrite the URL now so it looks like /A/B/a/b and you will still access those URL parameters in code and in macros.

Good luck

1 votesVote for this answer Mark as a Correct answer

John Sharp answered on August 7, 2015 14:36 (last edited on August 7, 2015 14:47)

Thanks both, I may have worded the question slightly oddly... so...

What I need is to have the URL entered by the user in the browser as any of the above, such as

/a/b/c/d/e/f/g/?type=a&param=b

From there I rewrite the url to /pages/pageType/TypeA/B/ (for example)

That bit I have working and the page is displayed correctly by Kentico. However I need the URL to remain as what was typed in and not be re-encoded to it's proper URL - everything Kentico is doing to display the page is correct however it's detecting the entered URL is not valid for the page and so is redirect me which is the part I want it to not do.

The issue I have at hand is that the URL is complicated and will be over 1000 different URL cominbations at the launch of the site and will grow exponentially as the site is populated by the client. Part of the URL is to know who the user is, where the user came from and what they're about to do (amongst other things) all of which are dynamic - I have a RegEx pattern which works and does the translation, my issue is the 301 redirect Kentico is doing "to be helpful". I just need it to serve the page on the rewritten URL and not an alias check.

I think this might explain what I'm trying to achieve...

If I put in web.config's URLRewrite section this:

<rewrite>
           <rules>
               <rule name="Redirect all to /" stopProcessing="true">
                   <match url="/path1" />
                   <action type="Rewrite" url="/" />
               </rule>
               <rule name="Redirect all to /" stopProcessing="true">
                   <match url="/path2" />
                   <action type="Rewrite" url="/" />
               </rule>
           </rules>
</rewrite>

What I would expect to see is the user type in <site>/path1 and have the homepage show, likewise for /path2 however the URL would not say "/" in the browser.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 7, 2015 14:44

Then a combination of entering the url you don't want processed in the settings and unchecking the Redirect document aliases to main URL property should work for you.

0 votesVote for this answer Mark as a Correct answer

John Sharp answered on August 7, 2015 14:49

Hi Brenden, I can see what you're saying, the problem there is that the not-to-be-processed-but-rewritten list is in the thousands

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 7, 2015 14:57

So would any part of the beginning URL be the same? If so, all you need to do is enter a starting directory and it will not process any of URLs below that directory.

0 votesVote for this answer Mark as a Correct answer

John Sharp answered on August 7, 2015 15:07

Nope - part of the joy of the system spec we have. Fundamentally, someone is the creator of a thing. They make the thing because their company requested it. The company was requested to make it on behalf of someone else.

The details of the thing can therefore be seen by the maker, a report from the makers' company or the requestor of the thing. All URLs may be valid and as the CMS allows you to move URLs and pages around there is no known final resting place for the pages that will contain links to the page that displays the details of "thing". Also, the thing report can be seen by the administrators of the system or any one that needs to know about "thing". All I can tell you is that the URL of the page is /UserAccount/ProductDetails.aspx?id=GUID.

I have two main issues, I need the URL the user typed in or clicked on as a requirement as it's that which will define the breadcrumb trail and this isn't the only instance where a single page may be accessed from a myriad of different URLs. The only thing I can be truly certain of is one of the parameters will tell my handler what to do.

Ideally, the requirement is for a URL to come from a browser, be rewritten by a module handler and have Kentico show the page that was requested after being rewritten from the module handler and not redirect the user to what it thinks is correct.

0 votesVote for this answer Mark as a Correct answer

Virgil Carroll answered on August 7, 2015 19:23

John,

I think you answered your own question. If you need the module handler to account for different URL types that have been defined or maybe defined in the future, you are probably going to have extend the current URL rewrite handler and add custom code. I would suggest having some location you can easily add new patterns into and then you will have to do some kind of matching routine, rewrite the URL the way you need it according to the match and then redirect.

I don't think your going to find an out of the box solution for this in Kentico (or frankly any other system) that is going to be flexible enough.

We had a project where we had to run redirects on over 5000 urls in another CMS. The customer did not want custom code so we ended up using the IIS rewrite module and a really large xml file to handle it.

0 votesVote for this answer Mark as a Correct answer

John Sharp answered on August 7, 2015 22:13

Hi Virgil,

Thanks for the idea. I will have a look; from what I can tell though, that's what I've already got in place. I'm getting the URL for the client in the first format and rewritting it correctly and then leaving it for Kentico to process however Kentico is detecting that URL A cannot be serviced by Page B as it's not in its' list of valid aliases so it's redirecting the user to the default URL of Page B. What I need is for Kentico to just leave the URL, not do the 301 redirect and display the page.

0 votesVote for this answer Mark as a Correct answer

Virgil Carroll answered on August 8, 2015 00:21

Id reach out to Kentico support to find the class you can override that behavior or spend some time reflecting on DLLs like the Core or Portal engine to find them

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.