다른 하위 폴더 폴더에서 파일을 찾도록 아파치를 얻는 방법은 무엇입니까?

다른 하위 폴더 폴더에서 파일을 찾도록 아파치를 얻는 방법은 무엇입니까?

나는 확실히 모드 재작성을 처음 접했습니다.

참고:- 여기서 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/filename.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

편집하다:

올리비에, 도와줘서 고마워요. 자세한 내용은 아래와 같습니다..

httpd.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://로컬호스트: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]

작동하는지 알려주세요 ;)

관련 정보