开发者

htaccess rewrite rule for javascript file with multiple periods

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开发者_如何学Python, all that gets rewritten for the file is jquery and everything else gets ignored

Any help is appreciated.


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]


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜