简体   繁体   中英

Regex rewrite rule for filename with dash

I got a filename like jquery.form.min.3.51.0-2014.06.20.js and want to change the following my rewrite rule to remove the dots, the dash and the digits.

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>

The rewrite rule does it jobs on filenames like scripts.min.4.4.2.js which is forwarded to scripts.min.js . But for the filename at the top, with the dash inside between the digits, the rule won't work.

My regex knowledge is too limited for this case. Could anybody give me a hint please?

You can use:

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.[\d-]+\.(js|css|png|jpg|gif)$ $1.$2 [L]
</IfModule>

请尝试以下操作:

RewriteRule ^(\D+)[\d.-]+(js|css|png|jpg|gif)$ $1$2 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM