现代收藏夹htaccess重写规则 [英] Modern favicons & htaccess rewrite rule

查看:72
本文介绍了现代收藏夹htaccess重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将所有新的favicon格式放置在我的网站的根目录中,而不是将它们放置在子文件夹中.

为了符合标准,因为某些浏览器/设备版本不使用html meta标记内指示的路径,而是无论如何尝试从网站根目录获取文件,所以我正在创建一个重写规则来重定向所有这些文件到实际位置-但只有这些文件.

到目前为止,我想出的是以下内容:

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]

这应该与以下所有文件匹配:

在此站点上测试规则> 时,该规则不匹配(请参见图片):

我想将此规则保持在同一行,并且由于大小标准的变化,我希望保持此动态(又名,而不是指定每个文件,而是尝试使用掩码).我怀疑我的正则表达式已关闭.

请针对我打算实现的功能,使用经过纠正的正则表达式模式提供帮助或提供解决方案.

解决方案

现代收藏夹图标+重写

以下是一种相当健壮的模式,用于通过重写来映射现代网站图标.

正则表达式模式,供参考

^(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)

此示例假定放置图标的重写目标位置是名为favicon的文件夹(或您想要的任何文件夹).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆