我想做以下重写:
如果文件名是/files/styles/*/*/*.*
,并且文件/files/*.*
不存在,则重写到另一个域。
在PERL中,regex应该是这样的:
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]
您可以使用%1
来获取先前rewritecsecond的反向引用。您可以尝试这样做:
# 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]