0

私はずっと探していましたが、自分に合った解決策が見つかりません。

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>
4

2 に答える 2

2

これが htaccess ファイルにある場合は、次の行を置き換えてみてください。

RewriteRule ^/files/(.*)$ /users/documents/$1 [L,R=301]

と:

RewriteRule ^/?files/(.*)$ /users/documents/$1 [L,R=301]

index.phpまた、ルーティング ルールの前に条件とルールを配置します。

于 2012-07-23T21:10:21.410 に答える
0

http://martinmelin.se/rewrite-rule-tester/にアクセスして、書き換えルールをテストしました。RewriteCond は何にも一致しないと言われましたが、ルールを削除すると一致します。

就業規則:

RewriteRule ^/?files/(.*)$ /users/documents/$1 [L,R=301]

これを htaccess ファイルの先頭に移動すると、問題が解決します。

于 2012-07-23T21:42:02.500 に答える