Apache mod_rewrite redirect with prefix

Posted by Marc on Server Fault See other posts from Server Fault or by Marc
Published on 2012-09-28T11:22:23Z Indexed on 2012/09/29 3:41 UTC
Read the original article Hit count: 415

I am newbie with Apache's mod_rewrite and I'm having some difficulties getting it to do what I want.

In my static directory, I have some javascript files (.js) with 2 kind of filename:

  1. xxxx.js which is the standard file name
  2. AT_xxxx.js (with prefixed filename) which has been duplicated from previous standard file name but also contains my customizations

I would like to parse requests for each standard requested javascript file (xxxx.js) to check if a customized file exists (AT_xxxx.js) including all sub-directories. Then, in this case, use the custom file instead of the standard file (perhaps by internal redirect).

I tried to figure this out for hours but something is still wrong.

Note: Also, I don't know how to find custom files in sub-directories.

DocumentRoot "/data/apps/dev0/custom/my_static"

<filesMatch "\\.(js)$">
  Options +FollowSymLinks
  RewriteEngine  on    
  RewriteCond %{DOCUMENT_ROOT}/AT_$1.js -f
  RewriteRule ^(.*[^/])/?$ %{DOCUMENT_ROOT}/AT_$1.js [QSA,L]
</filesMatch>

© Server Fault or respective owner

Related posts about apache2

Related posts about mod-rewrite