Apache RewriteRule标记代理NS

时间:2012-12-15 19:52:48

标签: apache mod-rewrite url-rewriting rewrite mod-proxy

我正在尝试编写以下规则(请参阅注释)

# Redirect example.org/sub/* to sub.example.org/* explicitly
RewriteCond %{REQUEST_URI} ^/sub(.+)$ [NC]
RewriteRule ^ http://sub.%{HTTP_HOST}%1 [L,R=301,NS]

# Redirect sub.example.org/* to example.org/sub/* internally
RewriteCond %{HTTP_HOST} ^sub\.(.+)$ [NC]
RewriteRule ^ http://%1/sub%{REQUEST_URI} [L,P,NS]

即使使用NS标志,当我点击sub.example.org/foo时,我得到了太多的重定向,这里是RewriteLog

applying pattern '^' to uri 'foo'
rewrite 'foo' -> 'http://example.org/sub/foo'
escaped URI in per-dir context for proxy, http://example.org/sub/foo -> http://example.org/sub/foo
forcing proxy-throughput with http://example.org/sub/foo
go-ahead with proxy request proxy:http://example.org/sub/foo [OK]

applying pattern '^' to uri 'sub/foo'
rewrite 'sub/foo' -> 'http://sub.example.org/foo'
explicitly forcing redirect with http://sub.example.org/foo
escaping http://sub.example.org/foo for redirect
redirect to http://sub.example.org/foo [REDIRECT/301]

等等

1 个答案:

答案 0 :(得分:0)

# Redirect example.org/sub/* to sub.example.org/* explicitly
RewriteCond %{REQUEST_URI} ^/sub(.+)$ [NC]
RewriteRule ^ http://sub.%{HTTP_HOST}%1 [L,R=301]

# Redirect sub.example.org/* to example.org/sub/* internally
RewriteCond %{HTTP_HOST} ^sub\.(.+)$ [NC]
RewriteRule - http://%1/sub%{REQUEST_URI} [L,P]

没有NS标志,只是短跑...... doh