我一直在尋找所有,我找不到適合我的解決方案。.htaccess重寫直接文件訪問
我想重定向http://example.com/files/file.ext - >http://example.com/users/documents/file.ext
無論我怎麼努力,當我直接上去的時候,它下載文件。該文件的GET請求也不會顯示在我的任何apache日誌中。我登錄了調試。
[編輯] 我試圖下載的文件有各種類型,包括ppt,pdf,xls,zip,doc等。我想將文件名重新寫入新URI的末尾。我也使用CodeIgniter,因此/ users/documents /是一個RESTy URI。
任何人都有修復?
這裏是我的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
RewriteBase/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
<IfModule mod_php5.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [N]
RewriteCond %{REQUEST_URI} ^/files/ [NC]
RewriteRule ^/files/(.*)$ /users/documents/$1 [L,R=301]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
你有沒有試過把你的'/ files /'規則移到重寫'index.php'上面的規則? – 2012-07-23 20:34:10
我剛試過。我以前有過,但沒有那個確切的規則。它仍然只是下載文件。 – Scone 2012-07-23 20:59:37
你是什麼意思「只是下載文件」。它是HTML,但沒有呈現?你有分配給擴展名「.ext」的處理程序嗎? – 2012-07-23 21:00:59