【问题标题】:mod_rewrite: search for domain root in subdirectorymod_rewrite:在子目录中搜索域根
【发布时间】:2013-07-18 14:03:13
【问题描述】:

在我的网站上,几乎每个网站都被缓存。一个静态的 htmfile 从 php 写入文件夹:

/__turbo_realcache/

如果访问者请求 mydomain.com/sitex.htm,则 apache 会首先查看是否在此处找到该文件:

/__turbo_realcache/sitex.htm

如果找到该文件,则将其交付给用户。如果缓存子文件夹中不存在该文件,则请求在内部重定向到 index.php(生成输出的位置)并通过 php 打印出来。

这很好用,但是在请求域根目录时它不起作用。所以如果用户调用

mydomain.com

我正在寻找的是: 如果访问者在其浏览器中请求 mydomain.com,则 htaccess 应搜索名为

的静态 html 文件

/__turbo_realcache/index.htm

如果找到,把它交给用户(怎么做?)。 如果没有找到,重定向到 index.php(已经可以使用)。

这是我完整的 htaccess:

RewriteEngine on

# redirect www to non www
#############################################################################
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


# search for realcache static files. if found stop and be happy.
#############################################################################
RewriteCond         %{DOCUMENT_ROOT}/__turbo_realcache/%{REQUEST_URI}  -f
RewriteRule  ^(.+)  %{DOCUMENT_ROOT}/__turbo_realcache/$1  [L]


# Don't apply to URLs that go to existing files or folders.
# Everything else goes to index.php where I decide what is shown to the user.
#############################################################################
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php

【问题讨论】:

    标签: apache mod-rewrite subdirectory


    【解决方案1】:

    在您的 realcache 静态文件 规则之后添加它。

    RewriteCond  %{REQUEST_URI}  ^/$
    RewriteCond  %{DOCUMENT_ROOT}/__turbo_realcache/index.htm  -f
    RewriteRule  ^  %{DOCUMENT_ROOT}/__turbo_realcache/index.htm  [L]
    

    【讨论】:

      猜你喜欢
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 2011-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多