如何使用 apache mod_rewrite 从请求的 URL 文件名中删除没有 md5 的文件名中的 md5?
How to remove md5 from the filename in the requested URL for the file name without md5 using apache mod_rewrite?
示例:
这 => URL 请求 ./any_folder/main.d25a1b054a0b0fbeb3def5a0ff50d01e.min.js
为此 => URL 请求 ./any_folder/main.min.js
我的 htaccess:
RewriteEngine On
# Remove md5 from asset files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+).([a-fA-F0-9]{32}).(.+)?(js|css)$ . [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
以上配置无效
让您的 htaccess 规则文件遵循以下方式。请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Remove md5 from asset files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##RewriteRule ^([^.]*)\.(?:[[:alnum:]]{32})\.([^.]*)\.(js|css)/?$ .. [L]
##Since following has worked for OP, so adding it here, commenting above.
RewriteRule ^(.+).([a-fA-F0-9]{32}).(.+)?(js|css)$ . [L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
示例:
这 => URL 请求 ./any_folder/main.d25a1b054a0b0fbeb3def5a0ff50d01e.min.js
为此 => URL 请求 ./any_folder/main.min.js
我的 htaccess:
RewriteEngine On
# Remove md5 from asset files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+).([a-fA-F0-9]{32}).(.+)?(js|css)$ . [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
以上配置无效
让您的 htaccess 规则文件遵循以下方式。请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Remove md5 from asset files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##RewriteRule ^([^.]*)\.(?:[[:alnum:]]{32})\.([^.]*)\.(js|css)/?$ .. [L]
##Since following has worked for OP, so adding it here, commenting above.
RewriteRule ^(.+).([a-fA-F0-9]{32}).(.+)?(js|css)$ . [L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]