简体   繁体   English

htaccess,如何使用gzip压缩+隐藏.html扩展名?

[英]htaccess, how can I use gzip compression + hide .html extensions?

I'm using 1and1 and I'm following this guide in order to compress as much of my website as I can: 我正在使用1and1,并且正在遵循本指南,以便尽可能地压缩我的网站:

http://mrrena.blogspot.com/2009/01/how-to-compress-php-and-other-text.html?showComment=1328550165472#c3296286447260746640 http://mrrena.blogspot.com/2009/01/how-to-compress-php-and-other-text.html?showComment=1328550165472#c3296286447260746640

I was previously also using my htaccess file to hide the .html extensions of each webpage. 以前,我还使用htaccess文件隐藏了每个网页的.html扩展名。 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. 现在,我已将新代码应用到通过php路由来压缩所有内容的过程中,我不再隐藏html扩展名,并且随后我的许多Web链接都被破坏了。 Here's a copy paste of my htaccess file. 这是我的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]
#

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

Performance 性能

This sort of thing is well beyond my area of expertise, ... 这种事情远远超出了我的专业领域,...

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. 使用PHP作为静态文件的包装器,每次访问文件时会增加〜100 mSec,这不是一个好主意。

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. 如果您需要有关如何调整应用程序的响应性的建议,请查看我的博客标签WebfusionPerformance ,它们为该托管服务提供商提供了一些非常具体的调整建议。 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. 我的博客在相同的托管基础​​结构上运行(Webfusion在同一家公司中只是另一个品牌)。您会发现我的Google Pagespeed得分为99/100,与Google主页达到的得分一样好,所以我怀疑您会对此有所改善。 (Yours is currently 56/100). (您目前的人数是56/100)。 My current rules are: 我当前的规则是:

AddType image/x-icon .ico
ExpiresActive On
ExpiresByType text/css        "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType image/x-icon    "access plus 1 month"
ExpiresByType image/jpeg      "access plus 1 week"
ExpiresByType image/gif       "access plus 1 week"
ExpiresByType image/png       "access plus 1 week"

<Files "sitemap.*">
   ForceType text/xml
</Files>

<Files "rss*">
   ForceType text/xml
</Files>

AddOutputFilter DEFLATE js css
AddOutputFilterByType DEFLATE text/html text/plain test/css text/xml application/xml

<FilesMatch "\.(css|js|gif|jpe?g|png|pdf)$">
   Header add "Cache-Control" "public, max-age=604800"
</FilesMatch>

<FilesMatch "\.(js|css|xml|html)$">
   Header append Vary Accept-Encoding
</FilesMatch>

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. 如果您有静态文件的PHP包装器,尤其是在共享托管服务上,则建议不要使用“必须重新验证”指令,因为您仍然要支付PHP映像启动罚款,并且需要处理If-Modified-SinceIf -None-Match请求标头,并正确发出304响应。

HTML links broken HTML链接已损坏

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. 您能否通过在示例前后提供一些具体的示例来更详细地准确描述哪些Web链接“断开”,那么也许我们可以给出具体的答复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM