我的网站应该尝试处理来自缓存子目录(/ app / storage / cache)的所有请求,以便从/app/storage/cache/two.html提供对/two.html的请求。
更多示例:/从/app/storage/cache/index.html提供/ /two.html从/app/storage/cache/two.html提供/ / folder从/app/storage/cache/folder/index.html提供
如果未找到文件/目录,则应使用php文件/app/router.php处理所有请求。
我尝试过的
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/storage/www/$1 [L]
RewriteRule ^(/)?$ /app/storage/www/$1 [L]
可以很好地捕获所有网址并提供正确的资源而不更改网址。现在抓到所有其他内容:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . app/router.php [L]
那也行得通,但是第一组条件不再起作用...
我可以通过三种方式来思考如何做到这一点。一种是在通过同一文件生成页面之前,通过router.php检查缓存。另两种方式涉及一些重写魔术。
我没有测试任何一个。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/storage/www/$1
#From this point on, the file/dir either exists or
#%{REQUEST_FILENAME} is now /app/storage/www/something
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/storage/www/ /app/router.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/app/storage/www/$1 !-f
RewriteCond %{DOCUMENT_ROOT}/app/storage/www/$1 !-d
RewriteRule ^(.*)$ /app/router.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/storage/www/$1 [L]
可以通过使用Apache的主配置文件(httpd.conf)而不是.htaccess文件来加快这两种方法,因为它不需要在每个请求中都搜索/读取.htaccess文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句