0

I'm looking for a rewrite rule that will handle a request such as

js/mysite/jquery.somelibrary.js or
js/mysite/jquery.validate.js or
js/mysite/somejsfile.js

What I have written so far handles the last case RewriteRule ^js/([a-z_]+)/([^\/.]+)\.js$ /site_specific_js.php?site=$1&file=$2 [QSA,L]

but on the first two, all that gets rewritten for the file is jquery and everything else gets ignored

Any help is appreciated.

2 Answers 2

1

All things is on te dot ([^\/.]+), just remove it

RewriteRule ^js/([a-z_]+)/([^\/]+)\.js$ /site_specific_js.php?site=$1&file=$2 [QSA,L]

or as in the $1

RewriteRule ^js/([a-z_]+)/([a-z0-9\.]+)\.js$ /site_specific_js.php?site=$1&file=$2 [NC,QSA,L]
Sign up to request clarification or add additional context in comments.

Comments

0

In:

RewriteRule ^js/([a-z_]+)/([^\/.]+)\.js$ /site_specific_js.php?site=$1&file=$2 [QSA,L]

Let's look at the filename, which is the important part:

([^\/.]+)\.js

Escaping the forward-slash isn't needed, since we're not using delimiters in our regex. Indeed, you use / unescaped elsewhere.

([^/.]+)\.js

Let's break it down:

(
  [^    # anything that's not:
    /   # a forward slash, or
    .   # a period
  ]  
  +     # one or more times
)  
\.      # then a period
js      # then "js"

Clearly, we can just remove . from the character class:

(
  [^    # anything that's not:
    /   # a forward slash
  ]  
  +     # one or more times
)
\.      # then a period
js      # then "js"

Ending up with:

RewriteRule ^js/([a-z_]+)/([^/]+)\.js$ /site_specific_js.php?site=$1&file=$2 [QSA,L]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.