Search code examples
mod-rewriteibmhttpserver

fallback aliased directory for static files that don't exist


Current configuration:

Alias   /wcsstore       "/opt/IBM/WebSphere/AppServer/profiles/demo/installedApps/WC_demo_cell/WC_demo.ear/Stores.war"

Example URL:

http://okdemo/wcsstore/test.txt

How do I make it first look for existing file /opt/IBM/test/test.txt and use the original directory as fallback?

Tried:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/wcsstore/(.*) /wcsstore-old/$1 [PT,L]

Alias   /wcsstore       "/opt/IBM/test"
Alias   /wcsstore-old       "/opt/IBM/WebSphere/AppServer/profiles/demo/installedApps/WC_demo_cell/WC_demo.ear/Stores.war"

But it seems that REQUEST_FILENAME does not resolve to /opt/IBM/test/test.txt. Everything is served from the fallback dir:

RewriteCond: input='/wcsstore/test.txt' pattern='!-f' => matched

Maybe I should concatenate: /opt/IBM/test%{REQUEST_URI} , but how to remove the /wcsstore word before concatenation?


Solution

  • In virtualhost context REQUEST_FILENAME is just the same as the request URL, since nothing has been mapped yet. You could prefix with %{DOCUMENT_ROOT}/ to poke around, or any other explicit path.

    To remove "wcstore", use a rewriteCond to split the string and then use %1 instead of the original variable

    RewriteCond %{REQUEST_URI} ^/wcsstore/(.*)
    RewriteRule /var/www/.../%1 ! -f