RewriteRule:将旧路径重定向到存档服务器并规范化为非www域?

我将旧服务器移动到archive.example.com,新服务器将继续在example.com上运行,而所有www URL都规范化为example.com或archive.example.com,并应处理尾随斜杠问题。 旧服务器有许多目录,因此除了一些将在新服务器上运行的目录外,所有内容都需要重定向到archive.example.com,同时保留路径信息。我不想重定向的目录以及将保留给新服务器的目录是: / (根) /静态的 /博客 /关于 例如: example.com => example.com www.example.com => example.com www.example.com/ => example.com/ example.com/blog => example.com/blog www.example.com/blog => example.com/blog www.example.com/blog/ => example.com/blog/ 所有其他目录应重定向到archive.example.com。例如: example.com/docs => archive.example.com/docs www.example.com/docs => archive.example.com/docs www.example.com/docs/ => archive.example.com/docs/ example.com/library/images => archive.example.com/library/images www.example.com/library/images => archive.example.com/library/images www.example.com/library/images/ => archive.example.com/library/images/ 这是我在httpd.conf文件中的内容:
ServerName example.com
ServerAlias www.example.com
UseCanonicalName On

# canonicalize www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ $1 [R=301]

# redirect everything to archive.example.com except for a few directories
RewriteCond  %{REQUEST_URI} !^(/|/static|/blog|/about)$
RewriteRule ^/(.*)$ http://archive.example.com/$1  [NC,R=301,L]
这是正确的和/或是否有更精确的方法?     
已邀请:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^gotactics.net$ [NC]
RewriteRule ^(.*)$ http://gotactics.net/$1 [L,R=301]
这将删除所有www。我确定你可以根据需要改变它。     
我相信我发现了我的问题 - RewriteRule重定向到了旧网站。 这就是我发布问题时的情况:
# redirect everything to archive.example.com except for a few directories
RewriteCond  %{REQUEST_URI} !^(/|/static|/blog|/about)$
RewriteRule ^/(.*)$ http://archive.example.com/$1  [NC,R=301,L]
......我把它重写为:
# redirect everything to archive.example.com except for a few directories
RewriteCond  %{REQUEST_URI} !^/$
RewriteCond  %{REQUEST_URI} !^/static.*$
RewriteCond  %{REQUEST_URI} !^/blog.*$
RewriteCond  %{REQUEST_URI} !^/about.*$
RewriteRule ^(.*)$ http://archive.example.com%{REQUEST_URI}  [NC,R=301,L]
这就是原因。 首先,正如您所看到的,我将单个重写条件分解为四个单独的条件,因为这将使我能够在新站点增长时干净地添加更多目录以进行排除。 您还会注意到我在/ static,/ blog /和/ about之后添加了一个点星,以便它在这些目录中的任何路径上匹配,而不仅仅是顶层。 最后,在RewriteRule行中,我从模式中删除了前导斜杠,并将尾随/ $ 1更改为%{REQUEST_URI}。我不需要在这里存储模式中的任何变量 - 我只需要更改服务器名称 - 所以不是从模式中提取路径,而是通过使用相同的%{REQUEST_URI}变量使其更明确。用于前四行。 顺便说一句:这首先引起我混淆的原因之一是因为Chrome有时会缓存DNS /路径信息 - 执行Ctrl-F5清除缓存会让您看到更改。     

要回复问题请先登录注册