0

私はこのようなディレクトリ構造を持っています

/ub/
/ub/img/
/ub/inc/

img基本的に、 URLを親ディレクトリに変更したいのですが(ub)

アクセスするとhttp://localhost/ub/mypic.jpg

まず、/ub/img/mypic.jpg存在する場合はそのファイルを取得してブラウザに渡します。そうでない場合は、 http://localhost/ub/index.php?img=mypic.jpgINTERNAL REDIRECTION を使用して渡します。

次に、index.php がそれを作成mypic.jpgして に保存し、ブラウザ/ub/img/に渡します。mypic.jpg

そのため、ファイルが存在するかどうかに関係なく、ブラウザーにhttp://localhost/ub/mypic.jpgは URL としてのみ表示されます。

これまでのところ、.htaccessファイルにこれがあります

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{DOCUMENT_ROOT}/ub/img/$1 -f
RewriteRule .+ /ub/img/$1 [L]

解決策を見つけるのに2日かかりますが、うまくいかないようです。

ありがとう、

編集 :

ねえ、これを持っている、 への要求は、私が期待したように、http://localhost/ub/app/file.phpに既に渡されています。index.php?uri=app/file.php

しかし、 へのリクエストhttp://localhost/ub/img/mypic.jpgは に渡されませんindex.php?uri=img/mypic.jpg。解決策はありますか?

Options -MultiViews +FollowSymLinks 
RewriteEngine On
RewriteBase /ub/

RewriteCond %{REQUEST_URI} ([^/]+)$
RewriteCond %{DOCUMENT_ROOT}ub/img/%1 -f
RewriteRule ^(.+)$ img/%1 [L]

RewriteCond %{REQUEST_URI} ([^/]+)$
RewriteCond %{DOCUMENT_ROOT}ub/inc/%1 -f
RewriteRule ^(.+)$ inc/%1 [L]

RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
4

1 に答える 1

0

次のようにしてみてください (/ub フォルダーの .htaccess に配置します)。

Options +FollowSymLinks
RewriteEngine on
RewriteBase /ub/

RewriteCond %{REQUEST_URI} ([^/]+\.jpg)$
RewriteCond %{DOCUMENT_ROOT}/ub/img/%1 -f
RewriteRule .+ - [L]

RewriteRule ^(.*)$ index.php?img=$1 
于 2012-05-24T06:32:18.363 に答える