rewrite appends previously visited link's path to other h:link

Splash Forums Rewrite Users rewrite appends previously visited link's path to other h:link

Tagged: 

This topic contains 4 replies, has 2 voices, and was last updated by  rewriteme 1 year ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #27228

    rewriteme
    Participant

    Steps:

    1) Add rules..
    cb.addRule(Join.path(“/home”).to(“/index.xhtml”));
    cb.addRule(Join.path(“/app/{id}/{name}”).to(“/page.xhtml”));

    2. Click on “/home” link and it works fine.
    3. Click on “/app/2/myname” link and it works fine.
    4. Click on “home” link but it appends /app/2/home so the link does not work

    How do I configure the rule with parameter so that it does not include it’s path for other links?

    Thank you

    #27229

    Could you please post your full configuration and the source code of the links that are causing the problems?

    #27230

    rewriteme
    Participant
    @Override
      public Configuration getConfiguration(ServletContext context) {
        ConfigurationBuilder cb = ConfigurationBuilder.begin();
    
        cb.addRule().perform(Log.message(Level.DEBUG, "Rewrite is active."));
    
        cb.addRule(Join.path("/home").to("/index.xhtml"));
        // cb.addRule(Join.path("/signin").to("/signin.xhtml"));
        // cb.addRule(Join.path("/login").to("/signin.xhtml"));
    
        // cb.addRule(Join.path("/signup").to("/signup.xhtml"));
    
        cb.addRule(Join.path("/aboutus").to("/aboutus.xhtml"));
        cb.addRule(Join.path("/contactus").to("/contactus.xhtml"));
    
        cb.addRule(Join.path("/accountrecovery").to("/accountrecovery.xhtml"));
    
        cb.addRule(Join.path("/user/{username}").to("/user.xhtml"));
    
        cb.addRule(Join.path("/sharestory").to("/app/storyadd.xhtml"));
    
        cb.addRule(Join.path("/useraccount").to("/app/useraccountedit.xhtml"));
        cb.addRule(Join.path("/editstory").to("/app/storyedit.xhtml"));
    
        cb.addRule(Join.path("/story/{storyid}/{story}").to("/shared.xhtml"));
    
        cb.addRule(Join.path("/tag/{tag}").to("/shared.xhtml"));
    
        return cb;
    
      }
    
    
    @Join(path="/signup", to="/signup.xhtml")
    @ManagedBean(name = "signUpUserAccountMBean")
    @RequestScoped
    public class SignUpUserAccountMBean
    

    After clicking on this link, the other links home, contactus do not work, i.e, the story/2/ get appended to be /story/2/home

    
    <h:link outcome="shared" includeViewParams="true"
      value="#{storyVar.storyName.i18N} - #{storyVar.title}">
      <f:param name="#{requestParamsMBean.REQ_PARAM_STORY}"
        value="#{storyVar.storyName.i18N} - #{storyVar.title}" />
      <f:param name="#{requestParamsMBean.REQ_PARAM_STORY_ID}"
        value="#{storyVar.id}" />
    </h:link>
    
    
    <td width="50%"><c:choose>
      <c:when test="#{signInMBean.userSignedIn}">
        <table border="0" width="100%">
          <tr align="right">
            <td><h:form>
                <h:outputLink value="home">#{i18nApp.header_home}</h:outputLink>
                | <h:outputLink value="sharestory"
                  rendered="#{signInMBean.userAppUser}">#{i18nApp.share_shareHeaderLink}</h:outputLink>  | 
                <h:outputLink value="user">#{userid}</h:outputLink>  | 
                <h:commandLink value="#{i18nApp.header_signout}"
                  action="#{signInMBean.doSignOut}" />
              </h:form></td>
          </tr>
        </table>
    
      </c:when>
      <c:otherwise>
        <table border="0" width="100%">
          <tr align="right">
            <td><h:outputLink value="home">#{i18nApp.header_home}</h:outputLink>
              | <h:outputLink value="signup">#{i18nApp.header_signup}</h:outputLink>
              | <h:outputLink value="signin">#{i18nApp.header_signin}</h:outputLink></td>
          </tr>
        </table>
      </c:otherwise>
    </c:choose></td>
    
    <tr align="center">
      <td><h:outputLink value="aboutus">#{i18nApp.footer_aboutUS}</h:outputLink>
        | <h:outputLink value="contactus">#{i18nApp.footer_contactUS}</h:outputLink></td>
    
    </tr>
    

    Thank you.

    • This reply was modified 1 year ago by  rewriteme.
    #27232

    You are using relative URLs in your h:outputLinks. If the current URL is /story/2/, the browser thinks that this is a directory. So if you are now using a relative link the browser will generate a link relative to this directory.

    You should always use absolute URL. Or use h:link instead.

    #27233

    rewriteme
    Participant

    Thank you, Christian!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Comments are closed.