Reputation: 813
I have a .htaccess file intended to get images, js and css from the corresponding folders just by getting the file extension. It should always get the files from /img, /js and /css in the root folder.
The lines I have for css and js work fine:
RewriteRule ^(([a-zA-Z0-9\-\.\/]+)/)?([a-zA-Z0-9\-\.]+).js$ js/$3.js [NC,L]
RewriteRule ^(([a-zA-Z0-9\-\.\/]+)/)?([a-zA-Z0-9\-\.]+).css$ css/$3.css [NC,L]
But when I try to use a similar line for the images I get a 403 "You don't have permission to access /img/ on this server." error:
RewriteRule ^(([a-zA-Z0-9\-\.\/]+)/)?(([a-zA-Z0-9\-\.]+).(jpg|png|svg|gif))?$ img/$3 [NC,L]
Everything work fine in the home page, but if you try to another page like mydomain.com/contact/ you get the 403 error. Even if you copy and paste the image URL in your browser it opens fine.
I tested the regular expression here and it's fine. What could be causing the problem?
Upvotes: 0
Views: 1609
Reputation: 43673
RewriteRule ([a-z0-9\-\.]+)\.(js|css)$ $2/$1.$2 [NC,L]
RewriteRule ([a-z0-9\-\.]+)\.(jpe?g|png|svg|gif)$ img/$1.$2 [NC,L]
Upvotes: 1