[solved] Rewriting occur on physical file request

Splash Forums PrettyFaces Users [solved] Rewriting occur on physical file request

This topic contains 7 replies, has 4 voices, and was last updated by  Lincoln Baxter III 6 years, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #17778

    mmanco
    Participant

    Hi,

    I am facing an unwanted behavior where a request to a physical file is rewrited.

    I have the following rule in pretty-config.xml

    <rewrite trailingSlash="append" toCase="lowercase" />

    Now when any file is requested the URL is rewrited and 404 status is returned.

    e.g.

    Requesting: http://example.com/css/style.css

    Resulting in: http://example.com/css/style.css/

    Is there any way to define a rule like with Apache’s mod_rewrite ?

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule .* - [L]

    RewriteRule (.*) router.jsf/$1

    Thanks in advance for any help.

    #20153
    #20154

    mmanco
    Participant

    Yes, I understand that it is possible to restrict it to a specific pattern but again I don’t get the idea why there should be an automatic rewriting to physical files.

    Now I should catch all file extensions in the match expression.

    What will happen if I miss one ?

    In case someone want to rewrite URL to a file he should map it.

    <url-mapping id="styles">
    <pattern value="/css/style.css" />
    <view-id>/themes/dark/style.css</view-id>
    </url-mapping>

    #20155

    domdorn
    Participant

    “I don’t get the idea why there should be an automatic rewriting to physical files.”

    Because PrettyFaces is basically just a Servlet Filter matching any Servlet Request.

    For it to be able match only non existing files, PrettyFaces would have to create a new File-Handle for every request and look if this request is a physical file. In a Servlet 3 environment, this even gets more complicated, as files could be packaged in different jars, so they don’t even really “exist” in the filesystem. From a performance view,

    this would be a real nightmare.

    I suggest you simply make your rewrite rules more precise (e.g. using regular expressions) so they don’t match physical files.

    #20156

    mmanco
    Participant

    Agree. Thanks.

    Here is the rule I used to prevent rewriting URLs pointing to files.

    <rewrite match="^((?!.*.w*).)*$" trailingSlash="append" toCase="lowercase" />

    #20157

    bohni
    Participant

    This should be corrected in the docs. The example pretty-config.xml (http://ocpsoft.com/docs/prettyfaces/3.1.0/en-US/html_single/#getstarted.prettyconfigxml) contains this rewrite rule with the trailingSlash.

    My first release without any eye candy worked, but as I added css and images, I ran into this problem, too.

    #20158

    bohni
    Participant
    #20159

    Glad you got it working… PS. We really do need some kind of full-fledged rewriting support in PrettyFaces, so if anyone here (or out there) is interested in getting involved, we’d be very glad to work together to make it happen!

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

You must be logged in to reply to this topic.

Comments are closed.