Rewrite not working

Splash Forums Rewrite Users Rewrite not working

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

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
  • #25199


    Hi all,

    I’m a newbie to this Url Rewriting beating his head hard to get this thing work.I’ve created a SampleConfigurationProvider class at location

    I’ve also created ConfigurationProvider file at location

    My complete project structure is:

    JAX-WS Web Services
    Deployment Descriptor:MyProject
    java Resources
    JavaScript Resources

    What I’m trying to do is that the index.jsp file contains a LINK to NewPages/newfile.html.
    So I want that when the link is clicked the URL shouldn’t be :

    Instead it should be like:

    The rule that I’ve added is:

    I’ve added a System.out.println(“Conf file loaded.”) msg in the Configuration file to test whether this file being loaded or not but the MSG isn’t getting displayed at the console.
    So is it that my configuration files aren’t placed properly ?

    I’ve attached my project.

    Plz help me out with this problem. My project has got stuck here.

    Thanks in advance 🙂

    • This topic was modified 8 years, 3 months ago by  rahulsoni.

    Looks like you placed the ServerLoader file in the wrong location. Try


    Instead of:




    Christian Sir,
    Thanks a Tonnnnnn,
    The Configuration file is now loading and the URL rewriting is now working. But I’m still not getting the desired URL effect.

    What I want is that when the Link in index.jsp is clicked the URL:

    The URL should be:

    But the URL that is being displayed is:

    My Rule is:
    .when(Direction.isInbound().and(Path.matches(“/11/article”))) .perform(Redirect.temporary(“/MyProject/NewPages/other.html”));

    What I want is that the URL should be the same as I’ve provided in the href of the anchor but the request should indirectly be forwarded to the desired location..

    How can I achieve this…

    Thanks in advance..

    • This reply was modified 8 years, 3 months ago by  rahulsoni.
    • This reply was modified 8 years, 3 months ago by  rahulsoni.

    Note, if you are using Rewrite 2.0.8, you can simply add the following annotation to your configuration provider, instead of using the service registration:

    public class MyConfigurationProvider ... {

    Also, I believe you may be misunderstood the purpose of Redirect 🙂 That will actually issue an HTTP redirect that sends the browser to a new location. I believe you want Forward, instead… but there is actually a simpler way to do this, using Join: Read the docs on ‘url mapping’ for an explanation.



    Thanks Lincoln Sir,
    I tried with Forward and Join, its working.

    Can u tell me the link where I can find details and explanations to all these Methods like JOIN,FORWARD,REDIRECT, etc..

    Thanks in advance


    Forwards and redirects are terms not specific to Rewrite itself. Join is a concept of Rewrite. You could have a look at the Rewrite documentation. But it’s currently not complete as we don’t find much time to work on it:


    Actually, even though our documentation on the website is not yet complete (working on it! sorry!) most of the JavaDocs are very comprehensive. So if you download the sources, or the JavaDocs, you should be able to see what each configuration element does!



    @lincoln: BTW: We should think about publishing the javadocs somewhere. I think this would useful for our users.



    Hello Lincoln Sir and Christian Sir,

    The URL Rewriting is doing fine now. But now there’s another problem.
    I’ve send my URL to SERVLET and after doing the processing the Servlet calls RequestDispatcher to FORWARD the request to a JSP page.

    The JSP page is also getting called but the STYLESHEET and JAVASCRIPT files linked to that JSP page are not loading.

    How can I fix this issue ??

    If the styling is included inside the <style> tags then its working but the external .css file isn’t being loaded.

    My RULE: .addRule(Join.path(“/{var1}/content/.*”).to(“/myservlet”))

    RequestDispatcher dis = request.getRequestDispatcher(“/mypage.jsp”);

    ISSUE: mypage.jsp is loading without its CSS and Javascript.

    Is it bcoz the stylesheets and scripts are loaded when the page is loaded into the browser while here the page is being called as a result of a forward request.

    On doing INSPECT ELEMENT on the browser I saw this msg:
    The stylesheet http://localhost:8080/OCPRewrite2.0.8/21/10/tutorial/java/style.css was not loaded because its MIME type, “text/html”, is not “text/css”.

    Thanks in advance


    Rewrite should not do anything to change the Content-Type header unless you specify otherwise, so I am guessing that the container you are using is not actually setting the content type, and that you may need to use a mime-mapping in your web.xml file.



    Tried adding mime-mapping to my web.xml but its still not working.

    When I type the URL to access the stylesheet as:

    I got this msg in the browser upon Element inspection:

    The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature. @ http://localhost:8080/OCPRewrite2.0.8/NewPages/style.css


    But the CSS file loads correctly? So it is send to you with a 200 OK response code? Where do you see this warning? If you load the file directly you should see the source code of the CSS file.



    Hello Lincoln Sir and Christian Sir,

    I got the sol’n to my prob. i was using Relative URL to call my CSS and JS files. But when request is Forwarded from Servlet to JSP, ABSOLUTE URL addressing is required. So I changed my URL to absolute and its working ..

    Thanks 🙂


    Glad you got it working!

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

The forum ‘Rewrite Users’ is closed to new topics and replies.

Comments are closed.