htaccess,如何使用 gzip 压缩 +隐藏 .html 扩展名?
我正在使用 1and1,并且遵循本指南,以便尽可能多地压缩我的网站:
我以前也使用过我的 htaccess 文件隐藏每个网页的 .html 扩展名。现在,我已经应用了新代码,通过 php 路由来压缩所有内容,我不再隐藏 html 扩展,并且我的许多 Web 链接随后被破坏。这是我的 htaccess 文件的复制粘贴。
Header unset Pragma
FileETag None
Header unset ETag
# cache images/pdf docs for 10 days
<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|css)$">
Header set Cache-Control "max-age=864000, public, must-revalidate"
Header unset Last-Modified
</FilesMatch>
# cache html/htm/xml/txt diles for 2 days
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
# tells the server to process all the file extensions specified through PHP5 for compression purposes
RemoveHandler .css
AddType x-mapp-php5 .php .shtml .html .htm .txt .js .css .ttf .svg .woff
#
Options +FollowSymLinks
RewriteEngine On
#
# REDIRECT /folder/index.html to /folder/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://weaverinnovations.com/$1 [R=301,L]
#
这类事情远远超出了我的专业领域,任何帮助以及如何解决冲突的解释将不胜感激。
谢谢!
I'm using 1and1 and I'm following this guide in order to compress as much of my website as I can:
I was previously also using my htaccess file to hide the .html extensions of each webpage. Now that I've applied the new code to compress everything by routing it through php, I am no longer hiding html extensions, and many of my weblinks are subsequently broken. Here's a copy paste of my htaccess file.
Header unset Pragma
FileETag None
Header unset ETag
# cache images/pdf docs for 10 days
<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|css)$">
Header set Cache-Control "max-age=864000, public, must-revalidate"
Header unset Last-Modified
</FilesMatch>
# cache html/htm/xml/txt diles for 2 days
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
# tells the server to process all the file extensions specified through PHP5 for compression purposes
RemoveHandler .css
AddType x-mapp-php5 .php .shtml .html .htm .txt .js .css .ttf .svg .woff
#
Options +FollowSymLinks
RewriteEngine On
#
# REDIRECT /folder/index.html to /folder/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://weaverinnovations.com/$1 [R=301,L]
#
This sort of thing is well beyond my area of expertise, and any help as well as an explanation of how to get around the conflict would be greatly appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表现
在这种情况下,我会“保持简单愚蠢”。我可能对此有更多的了解。使用 PHP 作为静态文件的包装器会在每次文件访问上增加约 100 毫秒的时间,这不是一个好主意。
如果您需要一些有关如何调整应用程序响应能力的建议,请查看我的博客标签,Webfusion 和 性能,为 提供了一些非常具体的调整建议这个托管提供商。我的博客在相同的托管基础设施上运行(Webfusion 只是同一家公司的另一个品牌名称)您会看到我的 Google Pagespeed 分数为 99/100,与 Google 主页的成绩一样好,所以我怀疑您会改进这一点。 (您当前的值为 56/100)。我当前的规则是:
如果您有静态文件的 PHP 包装器,尤其是在共享托管服务上,那么使用“必须重新验证”指令是不明智的,因为您仍然需要支付 PHP 图像启动罚款,并且需要处理 If-Modified-Since 和 If-None-Match 请求标头并正确发出 304 响应。
HTML 链接损坏
如果您每个问题问一个问题而不是两个问题,这确实很有帮助。您能否通过给出一些具体的前后示例来更详细地描述哪些网络链接被“损坏”,然后也许我们可以给出具体的回应。
Performance
Well in this case, I would "keep it simple stupid". I've probably more knowledge of the bowels of this. Using PHP as a wrapper for static files add ~100 mSec on each file access and not a good idea.
If you want some suggestions on how to tune you app for responsiveness have a look at my blog tags, Webfusion and Performance, which give some very specific tuning advice for this hosting provider. My blog runs on the same hosting infrastructure (Webfusion is just another brand name in the same company) You will see that I have a Google Pagespeed score of 99/100 which is as good as the Google home page achieves, so I doubt that you'll improve on this. (Yours is currently 56/100). My current rules are:
Using a "must revalidate" directive is ill-advised if you have a PHP wrapper for static files, especially on a shared hosting service, because you still pay the PHP image startup penalties and you need to process the If-Modified-Since and If-None-Match request headers and issue the 304 response correctly.
HTML links broken
It really helps if you ask one question per question and not two. Can you describe in more detail exactly what weblinks are "broken" by giving some specific before and after examples, then perhaps we can give a specific response.