Redirect xhtml to html

Splash Forums Rewrite Users Redirect xhtml to html

This topic contains 8 replies, has 2 voices, and was last updated by  Lincoln Baxter III 2 years, 9 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #25351

    defuchs
    Participant

    We would like to redirect all *.xhtml to *.html

    How would this be possible?

    I tried the following:
    config.addRule().when( Direction.isInbound().and( Path.matches( “{whatever}.xhtml” ) ) ).perform( Redirect.temporary( “{whatever}.html” ))

    Forward works with a join… but not as a redirect, shown before.

    Do you have any solution?

    #25352

    You want to redirect, not forward? Also, what exactly is not working? Your configuration doesn’t look correct, because {params} don’t match over / by default, additionally…

    If you look at the docs on Redirect, it documents that you must also prepend the Servlet context path:

       /**
        * Create an {@link Operation} that issues a permanent {@link Redirect} ( 301
        * {@link HttpServletResponse#SC_MOVED_PERMANENTLY} ) to the given location. If the given location is not the same as
        * {@link HttpServletRewrite#getAddress()}, this will change the browser {@link URL} and result in a new request.
        * 
        * <p>
        * Note that in order to redirect to a resource within the {@link ServletContext}, you must prepend the
        * {@link ServletContext#getContextPath()}.
        * 
        * <p>
        * For example:<br/>
        * <code>
        *    Redirect.permanent(contextPath + &quot;/example/location.html&quot;) <br>
        * </code>
        * 
        * <p>
        * The given location may be parameterized:
        * <p>
        * <code>
        *    /store/global
        *    /store/{category} <br>
        *    /store/{category}/item/{itemId} <br>
        *    ...
        * </code>
        * <p>
        * 
        * @param location {@link ParameterizedPattern} specifying the target location.
        * 
        * @see ConfigurationRuleParameterBuilder#where(String)
        */
       public static Redirect permanent(final String location)

    ServletContext.getContextPath() will be available from the context method parameter in your configuration provider.

    #25353

    Additionally, I think you can still use a Join for this:

    config
    .addRule(Join.path("/{whatever}.html").to("/{whatever}.xhtml").withInboundCorrection())
    .where("whatever").matches(".*")

    This should do what you want.

    #25354

    defuchs
    Participant

    Also with the slash in the beginning it does not work:
    config.addRule().when( Direction.isInbound().and( Path.matches( “/{whatever}.xhtml” ) ) ).perform( Redirect.temporary( “/{whatever}.html” ))

    What we need is to hide the .xhtml files from the user instead show html to do so and to not always do forwards when user bookmarks => redirects prevent them from adding bookmarks in the first place, so we need/want to do redirects.

    what i want is to redirect the followings:

    /aaa/bbb.xhtml to /aaa/bbb.html
    /aaa.xhtml to /aaa.xhtml

    no matter whatever is in front of xhtml just redirect it to html

    hope i could explain a bit clearer…

    #25356

    Do you actually have any HTML or XHTML files in your system?

    #25357

    defuchs
    Participant

    On server we have xhtml files,

    but we want the user to access html files.

    in the url ALWAYS should stay html and never xhtml

    so from something.xhtml he gets redirected to something.html

    #25358
    #25359

    defuchs
    Participant

    Which works, but does not do a redirect 🙁 => it’s a forward

    #25360

    Yes, it does a Forward from “.html” -> “.xhtml”, but it *does* Redirect from “.xhtml” -> “.html” as well.

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

You must be logged in to reply to this topic.

Comments are closed.