U
U
unsweet2018-03-26 08:41:00
htaccess
unsweet, 2018-03-26 08:41:00

How to exclude images from a rule in .htaccess?

The .htaccess file has the rule
#remove capital letters from links
RewriteCond expr "%{tolower:%{REQUEST_URI}} =~ /(.*)/"
RewriteRule [AZ] %1 [R=301,L]
How to fix it, so that it does not concern images, styles and scripts on the site? Those. if the link is to ABC.js or IMG.css or Qrt.jpg, then the rule would not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2018-03-26
@unsweet

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond expr "%{tolower:%{REQUEST_URI}} =~ /(.*)/"
RewriteRule [A-Z] %1 [R=301,L]

Note to the hostess: capitalization of filenames is considered bad practice in the world of web development, because almost always the site will run on a Linux server, the file system of which is case sensitive. Those. /ABC.js and /abc.js will be treated by Linux as different files. Lowercase letters, in turn, have become the standard in resource addresses, and there is a very high probability that at some stage of entering or processing the address, the case will be lost, as, for example, in your case.
Therefore, instead of solving the problem by modifying .htaccess, it would be more correct to convert all filenames in the file system to small case. Then any requests will be reduced to a small register and the files will be guaranteed to be available. This one-time solution is 100%, unlike the mixed-case filename solution, which you have to pay for more than once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question