【问题标题】:Serve static html for homepage otherwise serve to index.php为主页提供静态 html,否则提供给 index.php
【发布时间】:2019-11-28 20:31:02
【问题描述】:

我有一个非常标准的重写规则,可以通过索引将所有内容推送给我的 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 来提供,以提高加载速度。当请求 root 时,如何告诉 Apache2 服务 /path/to/some.html

我试过了

<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 处理。我做错了什么?

【问题讨论】:

    标签: apache apache2.4


    【解决方案1】:

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

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

    【讨论】:

    • 它不在 .htaccess 文件中它在虚拟主机配置文件中
    猜你喜欢
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2016-09-14
    相关资源
    最近更新 更多