现代收藏夹htaccess 重写规则 [英] Modern favicons & htaccess rewrite rule
问题描述
我没有将所有新的图标格式放在我网站的根目录中,而是将它们放在一个子文件夹中.
为了符合标准,由于某些浏览器/设备版本不使用 html 元标记内指示的路径,而是尝试从网站根目录获取文件,我正在创建一个重写规则来重定向所有这些文件到实际位置 - 但仅限这些文件.
到目前为止,我想出了以下几点:
RewriteEngine OnRewriteRule ^/((apple\-touch\-icon|android\-chrome|favicon|mstile)-([0-9]+)x([0-9]+).png|manifest\.json|browserconfig\.xml|favicon\.ico|(apple\-touch\-icon\-precomposed|apple\-touch\-icon).png|safari-pinned-tab.svg)$/favicon/$1 [L]
这应该匹配以下所有文件:
在测试规则
我想保持这条规则在同一行,并且由于大小标准的变化,我希望保持这个动态(也就是说,不是指定每个单独的文件,而是像我试图做的那样使用掩码).我怀疑我的正则表达式有问题.
请协助或提供带有更正正则表达式模式的解决方案,以实现我打算实现的目标.
Modern favicons + Rewrite
以下是使用重写映射现代网站图标的一种相当健壮的模式.
正则表达式,供参考
<块引用>^(browserconfig.xml|manifest.json|safari-pinned-tab.svg|(android-chrome|favicon|mstile)-[0-9]+x[0-9]+.png|apple-touch-icon(-precompressed.png|-[0-9]+x[0-9]+.png|.png)|manifest.json)$
用法:将其应用于重写规则 (htaccess)
此示例假设放置收藏夹图标的重写目标是名为 收藏夹
的文件夹(或您希望的任何文件夹).
RewriteRule ^(browserconfig.xml|manifest.json|safari-pinned-tab.svg|(android-chrome|favicon|mstile)-[0-9]+x[0-9]+.png|apple-touch-icon(-precompressed.png|-[0-9]+x[0-9]+.png|.png)|manifest.json)$/favicon/$1 [L]
Instead of having all the new favicon formats placed into the root directory of my website, I am placing them inside a subfolder.
To conform to the standards, as some browsers / device versions do not use the path as directed inside the html meta tags, but instead try to get the file from the website root anyway, I am creating a rewrite rule to redirect all these files to the actual location - but ONLY these files.
What I have come up with so far is the following :
RewriteEngine On
RewriteRule ^/((apple\-touch\-icon|android\-chrome|favicon|mstile)-([0-9]+)x([0-9]+).png|manifest\.json|browserconfig\.xml|favicon\.ico|(apple\-touch\-icon\-precomposed|apple\-touch\-icon).png|safari-pinned-tab.svg)$ /favicon/$1 [L]
This should match all of the following files :
When testing the rule at this site, the rule is not matched (see pic):
I would like to keep this rule on the same line, and due to the size standards changing, I wish to keep this dynamic (aka, instead of specifying each individual file, use a mask as I attempted to do). I suspect something with my regex is off.
Please assist or provide a solution with the corrected regex pattern for what I am intending to achieve.
Modern favicons + Rewrite
Following is a fairly robust pattern for mapping the modern favicon's using rewrite.
Regex pattern, for reference
^(browserconfig.xml|manifest.json|safari-pinned-tab.svg|(android-chrome|favicon|mstile)-[0-9]+x[0-9]+.png|apple-touch-icon(-precompressed.png|-[0-9]+x[0-9]+.png|.png)|manifest.json)$
Usage: apply it to a rewrite rule (htaccess)
This example assumes the rewrite destination where the favicon's are placed is a folder named favicon
(or whatever folder you wish).
RewriteRule ^(browserconfig.xml|manifest.json|safari-pinned-tab.svg|(android-chrome|favicon|mstile)-[0-9]+x[0-9]+.png|apple-touch-icon(-precompressed.png|-[0-9]+x[0-9]+.png|.png)|manifest.json)$ /favicon/$1 [L]
这篇关于现代收藏夹htaccess 重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!