我一直在寻找所有,我找不到适合我的解决方案。.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