2015-02-05 69 views
0

我正在使用一個框架,將所有URL重寫爲index.php,除非該文件或文件夾實際存在。.htaccess重寫基礎文件夾但不是內容

# Allow any files or directories that exist to be displayed directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Rewrite all other URLs to index.php/URL 
RewriteRule .* index.php/$0 [PT,L] 

但是,我有一個名爲'media'的目錄,以及一個URL爲'/ media'的頁面。我需要做到這一點,'/ media'會被路由到index.php,但在內部查看,'media'目錄會照常顯示。

所以:

http://example.com/some-page - routed through index.php (already does this) 
http://example.com/media - routed through index.php as well 
http://example.com/media/images/hello.jpg - asset served as usual 

我曾嘗試:

RewriteRule ^media$ index.php/media [PT,L] 

此列出像往常一樣 '媒體' 文件夾中的內容。

RewriteRule ^media/$ index.php/media 

這會導致重定向循環。

我不確定其他語法的工作原理。

回答

1

如果/media/images/hello.jpg是一個實際的文件,那麼RewriteCond %{REQUEST_FILENAME} !-f已經忽略了這一點。

如果沒有,那麼你將現有的路由規則之前把這個規則

RewriteRule ^media/.+$ - [NC,L]