Rewriting public assets to omit file extension

。_饼干妹妹 提交于 2019-12-13 06:00:45

问题


For the sake of formality, I want to trim my asset URIs so that file extensions are omitted.

For example, if I request /resources/stylesheets/common, Apache will return /resources/stylesheets/common.css. At the moment, I'm using the following rewrite to get this to work:

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}.css -f
RewriteRule ^ /%{REQUEST_URI}.css [L]

This works, as it should. However, I need to also do this for other resources, like images and scripts. For simplicity, I would like to avoid repeating this approach for every type of resource.

Question: What method can I use to achieve this in one rule? I'm thinking something along these lines (though this will not work, and I can see why - perhaps Apache doesn't like guess-work):

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}.(css|js|png) -f
RewriteRule ^ /%{REQUEST_URI}.%1 [L]

来源:https://stackoverflow.com/questions/16148830/rewriting-public-assets-to-omit-file-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!