我正在尝试将.htaccess
文件设置为从oldsite.com
重定向到newsite.com
,只有一个例外:如果用户访问http://oldsite.com/cal
,那么我希望它在根目录中显示cal.html
文件。
这是我得到的当前.htaccess
文件(不起作用):
Options +FollowSymlinks -MultiViews
RewriteEngine On
# this page can be served .. (not working)
RewriteRule /cal http://oldsite.com/cal.htm [L,NC]
# .. but rewrite everything else (this works fine)
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^(.*) http://newsite.com/$1 [R=301,L,NC]
它不起作用是什么意思?好吧,它只是将http://oldsite.com/cal
重定向到http://newsite.com/cal
,而不是显示http://oldsite.com/cal.html
答案 0 :(得分:3)
将其更改为:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^cal/? cal.htm [L,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^ http://newsite.com%{REQUEST_URI} [NE,R=301,L]
注释
oldsite
和newsite
住在不同的服务器上,您甚至不需要RewriteCond。RewriteRule ^(?!cal/?$) http://newsite.com%{REQUEST_URI} [NE,R=301,L]