我一直在寻找,我找不到适合我的解决方案。
我正在尝试重定向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>