Project

General

Profile

[Solved] mod_rewrite: repeated rewriting with url.rewrite-if-not-file

Added by flynn 5 days ago

I used url.rewrite-once

      url.rewrite-once = (
        "^/api/authorize/(.+)?$"   => "/api/authorize/index.php${qsa}",
        "^/api/(.+)?$"   => "/api/index.php${qsa}",
        "^/install/(.+)?$"   => "/install/index.php${qsa}",
        "^/pwa/getResource(.+)?$"   => "/pwa/index.php${qsa}",
        "^/pwa/getData(.+)?$"   => "/pwa/index.php${qsa}",
        "^/pwa(.+)?$"   => "/chromeos/$1",
        "^/(.+)?$"   => "/index.php${qsa}" 
      )

and $HTTP["url"] !~ "^..." to exclude static files - works as expected.

Then I tried the same with url.rewrite-if-not-file without exclude of static files and got multiple rewrites of the same path, e.g. /install/install/install/....

Because there is also a repeat variant url.rewrite-repeat-if-not-file, I expected url.rewrite-if-not-file to work like url.rewrite-once - am I wrong?


Replies (3)

RE: mod_rewrite: repeated rewriting with url.rewrite-if-not-file - Added by gstrauss 4 days ago

Because there is also a repeat variant url.rewrite-repeat-if-not-file, I expected url.rewrite-if-not-file to work like url.rewrite-once - am I wrong?

Yes, url.rewrite-if-not-file is different from url.rewrite-repeat-if-not-file

This works as expected for me in a simple test case, whether or not /install/index.php exists (as a dummy static file) in my document root.

server.document-root = "/dev/shm" 
server.port = 8080
server.modules += ("mod_rewrite")
url.rewrite-if-not-file = (
  "^/api/authorize/(.+)?$"   => "/api/authorize/index.php${qsa}",
  "^/api/(.+)?$"   => "/api/index.php${qsa}",
  "^/install/(.+)?$"   => "/install/index.php${qsa}",
  "^/pwa/getResource(.+)?$"   => "/pwa/index.php${qsa}",
  "^/pwa/getData(.+)?$"   => "/pwa/index.php${qsa}",
  "^/pwa(.+)?$"   => "/chromeos/$1",
  "^/(.+)?$"   => "/index.php${qsa}" 
)

=> Is there some interaction with your mod_fastcgi configuration which results in multiple rewrites of the same path, e.g. /install/install/install/... ? Is the fastcgi script index.php returning a redirect or internal rewrite? Do you get a similar result accessing /pwa... ?

BTW, there is no need to capture (.+) in your regexes except in the one case where you actually use $1.
.+ is fine to ensure there is a character, or even simply . to ensure there is a character following. Or you can omit that part entirely if you do not need to ensure that there is a subsequent character in the path, since you use (.+)?$
The anchored ^ prefix match is the same with or without (.+)?$, with the exception of "^/pwa(.+)?$" => "/chromeos/$1", where the capture is used. "^/pwa(.*)" => "/chromeos/$1",

RE: mod_rewrite: repeated rewriting with url.rewrite-if-not-file - Added by gstrauss 3 days ago

=> Is there some interaction with your mod_fastcgi configuration which results in multiple rewrites of the same path, e.g. /install/install/install/... ? Is the fastcgi script index.php returning a redirect or internal rewrite? Do you get a similar result accessing /pwa... ?

RE: mod_rewrite: repeated rewriting with url.rewrite-if-not-file - Added by flynn 2 days ago

I needed some time to figure out:

  • fastcgi is used
  • a not existing (and not needed) javascript file is requested outside /install
  • as you suspected the index.php returns a redirect only for this not existing file
  • this causes the multiple rewrites, because the redirect is relative, not absolute

With url.rewrite-once this does happen, because the path of the not existing javascript is exluded.

Sorry, I saw only the many lines of multiple rewrites in the browser log but overlooked the redirect - my fault.
Thank you for pointing me out.

Request can be closed.

    (1-3/3)