一个文件中的多个 ht 访问规则
multiple ht access rules in one file
我的站点应该尝试为来自缓存子目录 (/app/storage/cache) 的所有请求提供服务,以便从 /app/storage/cache/two.html[ 提供对 /two.html 的请求=12=]
更多示例:
/ 从 /app/storage/cache/index.html 开始提供
/two.html 来自 /app/storage/cache/two.html
/folder 从 /app/storage/cache/folder/index.html
如果没有找到 files/directories,它应该使用 php 文件处理所有请求 /app/router。php
我尝试过的:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/storage/www/ [L]
RewriteRule ^(/)?$ /app/storage/www/ [L]
在不更改 url 的情况下捕获所有 url 并提供正确的资源时效果很好。现在赶上其他一切:
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/
#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/ !-f
RewriteCond %{DOCUMENT_ROOT}/app/storage/www/ !-d
RewriteRule ^(.*)$ /app/router.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/storage/www/ [L]
这两种方法都可以通过使用 Apache 的主配置文件 (httpd.conf) 而不是 .htaccess 文件来加速,因为它不需要在每个文件上搜索 for/read .htaccess 文件请求。
我的站点应该尝试为来自缓存子目录 (/app/storage/cache) 的所有请求提供服务,以便从 /app/storage/cache/two.html[ 提供对 /two.html 的请求=12=]
更多示例: / 从 /app/storage/cache/index.html 开始提供 /two.html 来自 /app/storage/cache/two.html /folder 从 /app/storage/cache/folder/index.html
如果没有找到 files/directories,它应该使用 php 文件处理所有请求 /app/router。php
我尝试过的:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/storage/www/ [L]
RewriteRule ^(/)?$ /app/storage/www/ [L]
在不更改 url 的情况下捕获所有 url 并提供正确的资源时效果很好。现在赶上其他一切:
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/
#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/ !-f
RewriteCond %{DOCUMENT_ROOT}/app/storage/www/ !-d
RewriteRule ^(.*)$ /app/router.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/storage/www/ [L]
这两种方法都可以通过使用 Apache 的主配置文件 (httpd.conf) 而不是 .htaccess 文件来加速,因为它不需要在每个文件上搜索 for/read .htaccess 文件请求。