[英]Rewrite folder to another sub-folder inside that folder
I'm trying to convert a request from a folder, to another sub-folder inside that folder. 我正在尝试将请求从文件夹转换为该文件夹内的另一个子文件夹。 Let me explain:
让我解释:
Convert: localhost/myproject/build/css/style.css 转换: localhost / myproject / build / css / style.css
To: localhost/myproject/build/dev/css/style.css 到: localhost / myproject / build / dev / css / style.css
So, I need to add '/dev' to the request after 'build/' folder. 因此,我需要在“ build /”文件夹后的请求中添加“ / dev”。 What I have?:
我有的?:
RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteRule ^build/(.*) build/dev/$1
And I'm getting an infinite loop from Apache: 而且我从Apache得到无限循环:
[Thu Apr 24 17:56:39.721756 2014] [core:error] [pid 6980:tid 1660] [client ::1:55569] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error.
[2014年4月24日星期四17:56:39.721756] [core:error] [pid 6980:tid 1660] [client :: 1:55569] AH00124:由于可能的配置错误,请求超出了10个内部重定向的限制。 Use 'LimitInternalRecursion' to increase the limit if necessary.
必要时使用'LimitInternalRecursion'增加限制。 Use 'LogLevel debug' to get a backtrace.
使用“ LogLevel调试”获取回溯。
And I know what is happening, Apache is doing this: 而且我知道发生了什么,Apache正在这样做:
build/css/style.css (original request)
build/dev/css/style.css
build/dev/dev/style.css
build/dev/dev/dev/style.css
.... to the infinite
So I only need to catch an rewrite the request once. 因此,我只需要捕获一次重写请求即可。 Any idea?
任何想法?
This should work: 这应该工作:
RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteCond %{REQUEST_URI} !^/build/dev/(.*)
RewriteRule ^build/(.*) /build/dev/$1 [R=301]
The above will check and see if build/dev/
is in the url already, it is the it won't redirect. 上面将检查并查看
build/dev/
是否已在URL中,因为它不会重定向。 You were getting it to add dev/
if build/
was in the url, which caused the redirect loop. 如果在URL中包含
build/
,则会获得添加dev/
的权限,这会导致重定向循环。
You need to use a condition to skip adding /dev
once it has been added: 一旦添加了
/dev
您需要使用一个条件来跳过添加:
RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteRule ^build/((?!dev/).*)$ build/dev/$1 [L,NC]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.