私はこのようなディレクトリ構造を持っています
/ub/
/ub/img/
/ub/inc/
img
基本的に、 URLを親ディレクトリに変更したいのですが(ub)
、
アクセスするとhttp://localhost/ub/mypic.jpg
まず、/ub/img/mypic.jpg
存在する場合はそのファイルを取得してブラウザに渡します。そうでない場合は、 http://localhost/ub/index.php?img=mypic.jpg
INTERNAL 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]