Rewrite without middle part

Hi,

Im getting 404 errors on requests for .js and .css files

/assets/js/main.1704061619.js

should redirect to

/assets/js/main.js

Can’t figure out the way get the filename without the version part.

here’s my Caddyfile

:80 {

root ./public

log ./caddy.log
errors ./caddy-error.log

tls off

fastcgi / 127.0.0.1:9000 php {
	index index.php
}

rewrite {
	to {path} {path}/ /index.php?{query}
}

rewrite {
	if_op or
	if {file} ends_with .css
	if {file} ends_with .js
    to ...
}

Something like the following untested rewrite would probably work:

rewrite {
  if_op or
  if {file} ends_with .css
  if {file} ends_with .js
  r ^\/assets\/(js|css)\/main\.\d+\.(js|css)$
  to /assets/{1}/main.{2}
}

thanks, sorry my example wasn’t clear enough. I needed a regex to match the filename regardless of the path

This is what I ended up doing

rewrite {
    r  ^(.+)\.([\d\_]+)\.(js|css|png|jpg|gif)$
    to /{1}.{3}
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.