Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • rorythecheese 110 posts 56 karma points
    Apr 19, 2010 @ 18:25
    rorythecheese
    0

    alttemplate -> url rewriting

    Just wondering if anyone has had any luck removing the ?alttemplate=templatename part of the url using the url rewriting module but keeping the new (alt) template inplace?

    So for our mobile sites we redirect to a m. subdomain and then add alttemplate=Mobile-Home to the end. What i'd like is so that when someone's on the mobile subdomain then it'll strip the alttemplate bit from the url, keeping them clean.

    So far i've only got it to redirect to the alttemplate-less page but i can't get it to just strip/rewrite the end. It will only work if i have the redirect="Application" line in the rewrite rule.

    <rewrites>
        <add name="mobile"
        virtualUrl="(http://|)(www.|)(.*?)/(.*)\?alttemplate=Mobile-(.*)"
        redirect="Application"
        rewriteUrlParameter="IncludeQueryStringForRewrite"
        destinationUrl="/$4"
        ignoreCase="true"/>
    </rewrites>

    Anyone have any ideas or know if this is possible or not?

    Cheers.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 20, 2010 @ 02:56
    Lee Kelleher
    0

    Hi Rory,

    Try changing the "rewriteUrlParameter" parameter value to "ExcludeFromClientQueryString"?

    Cheers, Lee.

  • rorythecheese 110 posts 56 karma points
    Apr 20, 2010 @ 11:42
    rorythecheese
    0

    Hi Lee, 

    I've tried that but doing so send's it into a redirect loop. If i take out the redirect line from the rule then the whole thing stops working..

    Cheers.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 20, 2010 @ 14:43
    Lee Kelleher
    0

    Hi Rory,

    I haven't tested this, but thinking that you might want to try re-working the rewrite rule to something like this:

    <add name="mobile" virtualUrl="(http://|)(www.|)(.*?)/(.*)/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/$4?altTemplate=Mobile-$5" ignoreCase="true" /> 

    This would remove the "altTemplate" querystring from the URL, but would require you to include an extra URL segment for the template's suffix; (whereas the template's prefix is "Mobile-").

    Not entirely sure that it will work, but it's worth a try.

    Cheers, Lee.

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Apr 21, 2010 @ 01:18
    Douglas Robar
    3

    Quick hack... use extensionless urls and then you can just slap the template name on the end!

    As you know, both of these are equivalent and produce the same result:

    The difficulty is inserting the template alias before the .aspx portion of the url.

    BUT... if you use exentionless urls with umbraco you don't have to do that and your life is much simpler:

    cheers,
    doug.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 21, 2010 @ 10:58
    Lee Kelleher
    0

    Quick follow on from Doug's suggestion... if you can't use extensionless URLs (for whatever reason), then you could try this:

    <xsl:value-of select="umbraco.library:Replace(umbraco.library:NiceUrl(@id), '.aspx', concat('/mobile-home', '.aspx'))" />

    The only "gotcha" is if you have multiple ".aspx" strings in the URL (can't think of a reason why, but it's possible - maybe a subdomain?)

  • rorythecheese 110 posts 56 karma points
    Apr 22, 2010 @ 18:31
    rorythecheese
    0

    Cheers guys, only just got around to looking into this again. 

    <add name="mobile" 
    virtualUrl="(http://|)(www.|)(.*?)/(.*)/(.*)" 
    rewriteUrlParameter="ExcludeFromClientQueryString" 
    destinationUrl="~/$4?altTemplate=Mobile-$5" 
    ignoreCase="true" />    

    This works in that it rewrites the url properly, problem is i've got a load of different mobile alttemplates and no way of getting their names from the rest of the url.

    As you know, both of these are equivalent and produce the same result:

    I didn't but i do now :) This is really good actually. Should be able to ge this working i think as we have extension-less url's set up. 

    Nice one.

  • Carlos 338 posts 472 karma points
    Jan 28, 2011 @ 18:10
    Carlos
    0

    I know this solution was made a while ago but have a quick question.

    I like the idea of the /mobile-home.aspx or /mobile-home, but it there a way to write that so when the page comes up it adds something like http://localhost/mobile/mypage, but the mobile home template is chosen.

     

    I have no idea if this will even work.

    OR is there another way to get the URL or to get Umbraco to have the ability to do something like http://localhost/mypage and the same content show up on the http://localhost/mobile/mypage, without having to duplicate content?

    I hope I explained my question correctly.

    Thanks

  • Davide 9 posts 29 karma points
    Jan 26, 2015 @ 11:28
    Davide
    0

    Hi all, 

    I was using the URL rewriting in UMBRACO 4.7.2 on my custom Global.asax file into the Application_BeginRequest method. Now I'm trying to upgrade to version 6.0.0 where I saw that I have to change my custom Global.asax to inherit from Umbraco.Web.UmbracoApplication.

    No problems so far in general in the application, but when the global.asax triggers the HttpContext.Current.RewritePath(URL), after migrating to version 6, the method does not rewrite the URL at all. It does not give any error or exception, it simply doesn't rewrite the URL, and consequently the system returns 404 , file not found.

    Any ideas about it? Did the version 6 of Umbraco stop to support the HttpContext.Current.RewritePath method in its new Global.asax?

    Thanks in advance to all of you!

  • Carlos Mosqueda 242 posts 433 karma points
    Jan 26, 2015 @ 17:42
    Carlos Mosqueda
    0

    @Davide,

    May I ask why you would be doing this in the Global.asax and not in the Web.config?

    Is there anything in your logs that states an issue, even if you are not getting an exeption the logs might let you know of an issue.

     

  • Davide 9 posts 29 karma points
    Jan 27, 2015 @ 10:24
    Davide
    0

    Hi and thanks for your reply!

    I chose the HttpContext.Current.RewritePath solution in the Global.asax because of the particular customised situation. I also have to show long titles (with possible bad characters to replace) in the rewritten address... I thought the web.config solution was a better way to rewrite URLs in more "static" cases, where you can simply map  ADDRESS x -> ADDRESS y, with a more limited set of combinations..but I could be wrong...

    No logs in "umbraco\App_Data\Logs" folder about this issue. 

    In general, as you said, I don't know if the RewritePath is the best solution (maybe not) but it worked till version 4.9.0 of Umbraco. Only since the Global.asax has to inherit from Umbraco.Web.UmbracoApplication instead of HttpApplication it stopped working...this is strange...

  • Carlos Mosqueda 242 posts 433 karma points
    Jan 27, 2015 @ 16:40
    Carlos Mosqueda
    0

    Hi Davide,

    I am not sure if this helps but here is some documenation about the application start up Event Handler and some of the changes that occured from 4.9 to 4.10 and to 6.0+  You might want to take a look at this. I am not sure if this is causing anything on your end, which is may be, but it looks like in 4.10 ApplicationStartupHandler   and moved the implementation of an IApplicationEventHandler

     I have a feeling this is because of the MVC approach Umbraco moved to.  I have a feeling the links below may help you out..

    http://our.umbraco.org/documentation/Reference/Mvc/using-ioc 

    http://our.umbraco.org/documentation/Reference/Events/application-startup

    http://our.umbraco.org/wiki/reference/api-cheatsheet/using-iapplicationeventhandler-to-register-events

    Here is one from Stack overflow talking about a few of the new methods for the Global.asax

    .http://stackoverflow.com/questions/15872770/global-asax-in-umbraco-6

     

     

     

     

     

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft