【发布时间】:2013-12-15 13:02:47
【问题描述】:
这是我的.htaccess 文件。如果 url 匹配它们,它应该从 assets 文件夹传递静态文件。否则,一切都应该重定向到index.php。
请注意,此处的 url 不包含 assets 作为 segemnt。所以example.com/css/style.css 指向assets/css/style.css。
RewriteEngine on
# disable directory browsing
Options -Indexes
# static assets
RewriteCond %{DOCUMENT_ROOT}/assets/$1 -f
RewriteRule ^(.*)$ assets/$1 [L]
# other requests to index.php
RewriteRule !^asset/ index.php [L]
不幸的是,像 example.com/assets/css/style.css 这样的 url 也会传递文件,因为对于那个 url,我的规则都不适用,并且应用了 Apache 的默认行为来传递文件。
所以我尝试将最后一行更改为此。我认为这会起作用,因为上述规则中的 [L] 标志应该停止执行资产 URL 并传递它们。
RewriteRule ^(.*)$ index.php [L]
相反,并非所有请求都被重定向到index.php,即使是像example.com/css/style.css 这样的静态资产。为什么 flag 不停止执行重写规则以及谁来解决我的问题?
【问题讨论】:
标签: apache mod-rewrite redirect web-applications assets