Apache で異なるサブフォルダー内のファイルを検索するにはどうすればよいでしょうか?

Apache で異なるサブフォルダー内のファイルを検索するにはどうすればよいでしょうか?

私は mod-rewrite に関してはまったくの初心者です。

注: ここでは URL が共通であり、すべてのフォルダーとサブフォルダーは同じホスト上にあります。

ユーザーがページにアクセスするために使用するURLはhttp://myurl.com/1234/filename.jpg

ここで、サブフォルダーの名前は一意の整数であり、別のアプリケーションによって動的に生成されます。

サブフォルダーには、個々のユーザーに固有の画像が保存されます。

フォルダ構造は次のようになります

main1 = document root
main2 is another folder within main1 or document root.

/main1/1234/filename.jpg
/main1/5678/filename.jpg
/main1/2345/filename.jpg
/main1/1212/filename.jpg
/main1/main2/2367/filename.jpg
/main1/main2/8790/filename.jpg
/main1/main2/9966/filename.jpg

そこで、ユーザーが入力しようとしたときにルールを書き換えたいのですが

http://myurl.com/1234/filename.jpg,

書き換えルールは、ファイルがどこにあるかを調べてリクエストを処理する必要があります。したがって、リクエスト http:/myurl.com/1234/filename.jpg の場合、実際のページは /main1/1234/filename.jpg にあり、そのフォルダーからそのページを処理する必要があります。

したがって、他のユーザーがhttp://myurl.com/9966/ファイル名.jpg、次の宛先からページを提供する必要があります /main1/main2/9966/filename.jpg

質問がまだ明確でない場合はお知らせください。

これは私がこれまでやってきたことですが、まったく機能しません。

RewriteCond         {DOCUMENT_ROOT}/%{REQUEST_FILENAME}  -f
RewriteRule  ^(.*)$ {DOCUMENT_ROOT}/$1  [L]  
RewriteCond         {DOCUMENT_ROOT}/main2/%{REQUEST_FILENAME}  -f
RewriteRule  ^(.*)$ {DOCUMENT_ROOT}/main2/$1  [L]

どんな助けでも本当にありがたいです

編集 @ShaneMadden 詳細を確認してください。設定は .htaccess ファイルにあります。.htaccess の詳細を確認してください。

RewriteEngine on 
RewriteCond %{REQUEST_URI} ^/main1/\/. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(main1)(/\/.+)$ $1/main2/\$2

編集:

オリヴィエさん、助けてくれてありがとう。詳細は以下をご覧ください。

confファイル

DocumentRoot  "/WebServer/Documents"

ディレクトリ一覧

ls -lRt /WebServer/Documents/

-rw-r--r--   index.html 
-rw-r--r--   .htaccess
drwxrwxrwx main1
drwxrwxrwx 456231 (Is a folder)


./WebServer/Documents/main1/:
drwxrwxrwx 566432

./WebServer/Documents/456231/:
-rwxrwxrwx  one.jpg

./WebServer/Documents/main1/566432:
-rwxrwxrwx one.jpg

.htaccess ファイル

RewriteEngine on

RewriteCond  %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}  -f
RewriteRule  (.*) %{DOCUMENT_ROOT}/$1  [L]
RewriteCond  %{DOCUMENT_ROOT}/main1/%{REQUEST_FILENAME}  -f
RewriteRule  (.*) %{DOCUMENT_ROOT}/main1/$1  [L]

アクセスURL -->http://localhost:80/

::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/ -> 
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri ''
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents//WebServer/Documents/' pattern='-f' => not-matched
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/ -> 
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri ''
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents/main1//WebServer/Documents/' pattern='-f' => not-matched
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (1) [perdir /WebServer/Documents/] pass through /WebServer/Documents/
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/index.html -> index.html
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri 'index.html'
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents//WebServer/Documents/index.html' pattern='-f' => not-matched
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/index.html -> index.html
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri 'index.html'
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents/main1//WebServer/Documents/index.html' pattern='-f' => not-matched
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (1) [perdir /WebServer/Documents/] pass through /WebServer/Documents/index.html

2.)http://localhost:80/566432/one.jpg

::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] add path info postfix: /WebServer/Documents/566432 -> /WebServer/Documents/566432/one.jpg
::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/566432/one.jpg -> 566432/one.jpg
::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri '566432/one.jpg'
::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents//WebServer/Documents/566432' pattern='-f' => not-matched
::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] add path info postfix: /WebServer/Documents/566432 -> /WebServer/Documents/566432/one.jpg
::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/566432/one.jpg -> 566432/one.jpg
::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri '566432/one.jpg'
::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents/main1//WebServer/Documents/566432' pattern='-f' => not-matched
::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (1) [perdir /WebServer/Documents/] pass through /WebServer/Documents/566432

答え1

もうすぐできました!!

「%」を忘れました!!

単独では以下^(.*)$と同じなので、(.*)次のように動作するはずです:

RewriteEngine On
RewriteCond  %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}  -f
RewriteRule  (.*) %{DOCUMENT_ROOT}/$1  [L]  
RewriteCond  %{DOCUMENT_ROOT}/main2/%{REQUEST_FILENAME}  -f
RewriteRule  (.*) %{DOCUMENT_ROOT}/main2/$1  [L]

うまくいくかどうか教えてください ;)

関連情報