2011-09-19 2 views
0

다음 재 작성을 수행하려고합니다.Apache를 사용하면 서버 변수의 파생어에서 RewriteCond를 수행 할 수 있습니까?

파일 이름이 /files/styles/*/*/*.*이고 /files/*.* 파일이없는 경우 다른 도메인으로 다시 작성하십시오.

PERL 정규 표현식으로 이것을 수행하려면 다음과 같이됩니다.

s/\/files(\/styles\/[^\/]+?/[^\/]+?)(\/.*)$/\/files$2/ 

Apache mod_rewrite로 가능합니까?

RewriteCond %{REQUEST_FILENAME} ^files/styles.*$ 
RewriteCond [derivative of %{REQUEST_FILENAME}] !-f 
RewriteRule (.*)$ http://example.com/$1 [R=301,L] 
라인을 따라 뭔가가 있습니다.

답변

0

의 라인을 따라 뭔가 당신은 이전한다 RewriteCond의 역 참조를 얻기 위해 %1을 사용할 수 있습니다. 다음과 같이 시도해보세요.

# Is the request */files/styles/*/*/*.* 
# Set a backreference which will be the docroot (*)/files.... 
# Set a backreference which will be the filename (*.*). 
RewriteCond %{REQUEST_FILENAME} ^(.*)/files/styles/[^/]+/[^/]+/(.+)$ 
# Check to see if backreference exists. 
RewriteCond %1/files/%2 !-f 
# Redirect. 
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] 
관련 문제