Pedro Lobito
Pedro Lobito

Reputation: 99001

Apache ProxyPass - Regex to Exclude Files

I'm trying to exclude all files starting with "dgg-" and ending in ".xml", example: dgg-file-1.xml from using the apache proxy.

This works:

ProxyPass /myfile.xml ! # single file
ProxyPass /directory ! # all files inside dir

This doesn't work:

ProxyPass /dgg-(.*)\.xml !

How can I achieve this ?

ps- I'm using this code inside the httpd.conf->virtualhost not .htaccess.

Upvotes: 10

Views: 17031

Answers (2)

Reddymails
Reddymails

Reputation: 823

I had a situation where I wanted few images to be picked from Apache webserver and few images to be included from the application server (In my case Jboss). So I wanted one regex that had to both exclude and include. Here is what I added to httpd.conf file under VirtualHost tag.

There are some css and js files which are in jsf jars and jenia popup jars which we will not find on webserver. So reach out to app server.The regexp is looking for all *.js and *.css urls but exclude any urls that have /jenia4faces and /faces in it. This is to make sure scripts like this /MYWEBAPP/jenia4faces/popup/popupFrame/js/popupFrame.js and /MYWEBAPP/faces/myFacesExtensionResource/tabbedpane.HtmlTabbedPaneRenderer/11302665/dynamicTabs.js are still pulled from app server . Rest all .js and .css will be served by webserver.

  ProxyPassMatch ^(/MYWEBAPP/(?!jenia4faces).*\.js)$ !
  ProxyPassMatch ^(/MYWEBAPP/(?!faces).*\.css)$ !
  ProxyPassMatch ^(/MYWEBAPP/(?!jenia4faces).*\.js)$ !
  ProxyPassMatch ^(/MYWEBAPP/(?!faces).*\.css)$ !

where /MYWEBAPP is my web apps root context. Also (?!faces) is to tell if the url doesnt not have "faces" in the url path.

Upvotes: 3

fge
fge

Reputation: 121810

Use ProxyPassMatch. ProxyPass expects fully written path elements, it does not accept regexes.

As ProxyPassMatch takes a regex, this means you must also anchor it:

ProxyPassMatch ^/dgg-[^.]+\.xml$ !

Upvotes: 17

Related Questions