首页 > 解决方案 > 为主页提供静态 html,否则提供给 index.php

问题描述

我有一个非常标准的重写规则,可以将所有内容推送到我的 CMS 处理的索引中。

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME}/index.html !-f
  RewriteCond %{REQUEST_FILENAME}/index.php !-f
  RewriteRule . index.php [L]
</IfModule>

我想将我的主页和几个基石博客作为静态 html 来提供,以提高加载速度。/path/to/some.html当请求 root 时,我如何告诉 Apache2 服务?

我试过了

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteBase /

  RewriteCond %{REQUEST_URI} "^/$"
  RewriteRule ^/$ /path/to/some.html

  RewriteCond %{REQUEST_URI} "^/some/important/path$"
  RewriteRule ^/$ /path/to/some/other.html

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME}/index.html !-f
  RewriteCond %{REQUEST_FILENAME}/index.php !-f
  RewriteRule . index.php [L]
</IfModule>

但这一切仍然通过索引提供服务并由 CMS 处理。我究竟做错了什么?

标签: apacheapache2.4

解决方案


看起来这是在 .htaccess 中,所以每次更改后,处理将使用新路径重新开始。当规则真的知道它想要成为最终规则时,添加了 [END] 标志以帮助缩短这种循环。

相比之下,现有的 [L] 标志仅停止当前轮的处理。


推荐阅读