0

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

# 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]

开启和开启

4

1 回答 1

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

于 2012-12-15T20:03:16.350 回答