Create Rule to Redirect\Change URL in the Address Bar of the Browser

Splash Forums Rewrite Users Create Rule to Redirect\Change URL in the Address Bar of the Browser

This topic contains 2 replies, has 2 voices, and was last updated by  RB 2 minutes ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #27453


    Is it possible to redirect/change the url in the address bar of the browser? I want that if the user type ” /Recommended.xhtml?recd=teste ” on the address bar it got redirected to ” /recommended/teste “. I want only ” /recommended/teste ” to be visible on the address bar of the browser even if the user directly input ” /Recommended.xhtml?recd=teste “. The code below is working but it doesn’t change the link in the address bar.

    This is what I got so far:

    import javax.servlet.ServletContext;
    import org.ocpsoft.logging.Logger.Level;
    import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
    import org.ocpsoft.rewrite.config.Configuration;
    import org.ocpsoft.rewrite.config.ConfigurationBuilder;
    import org.ocpsoft.rewrite.config.Direction;
    import org.ocpsoft.rewrite.config.Log;
    import org.ocpsoft.rewrite.servlet.config.Forward;
    import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
    import org.ocpsoft.rewrite.servlet.config.Path;
    import org.ocpsoft.rewrite.servlet.config.Redirect;
    import org.ocpsoft.rewrite.servlet.config.rule.Join;
    public class ApplicationConfigurationProvider extends HttpConfigurationProvider
       public Configuration getConfiguration(ServletContext context)
          return ConfigurationBuilder.begin()
       public int priority()
          return 10;

    In the web.xml

       <filter-name>OCPsoft Rewrite Filter</filter-name>
       <filter-name>OCPsoft Rewrite Filter</filter-name>

    You can use .withInboundCorrection() on a Join for this.

    Also note that should not use query parameters in the .to() part of your rule. Path parameters are automatically transformed in a query parameter with the name of the parameter. So the rule should look like this:


    I hope this helps.



    Thanks Christian! It worked like a charm!

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

You must be logged in to reply to this topic.

Comments are closed.