Apache mod_rewrite:在子目录中搜索域根
在我的网站上,几乎每个站点都被缓存。静态HTML文件从php写入文件夹: /__turbo_realcache/ 如果访问者请求mydomain.com/sitex.htm,apache会首先查看是否在此处找到该文件:Apache mod_rewrite:在子目录中搜索域根,apache,mod-rewrite,subdirectory,Apache,Mod Rewrite,Subdirectory,在我的网站上,几乎每个站点都被缓存。静态HTML文件从php写入文件夹: /__turbo_realcache/ 如果访问者请求mydomain.com/sitex.htm,apache会首先查看是否在此处找到该文件: /__turbo_realcache/sitex.htm 如果找到该文件,则会将其传递给用户。如果缓存子文件夹中不存在该文件,则请求会在内部重定向到index.php(生成输出的位置),并通过php打印出来 这可以很好地工作,但是当请求域根目录时它就不工作了。因此,如果用户调用
/__turbo_realcache/sitex.htm
如果找到该文件,则会将其传递给用户。如果缓存子文件夹中不存在该文件,则请求会在内部重定向到index.php(生成输出的位置),并通过php打印出来
这可以很好地工作,但是当请求域根目录时它就不工作了。因此,如果用户调用
mydomain.com
我要搜索的是:
如果访问者在其浏览器中请求mydomain.com,则htaccess应搜索名为
/__turbo_realcache/index.htm
如果找到,请将其交给用户(如何操作?)。
如果找不到,请重定向到index.php(已在工作)
这是我的完整访问权限:
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
在realcache静态文件规则之后添加此项
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{DOCUMENT_ROOT}/__turbo_realcache/index.htm -f
RewriteRule ^ %{DOCUMENT_ROOT}/__turbo_realcache/index.htm [L]