我尝试使用RedirectMatch,但我的代码不起作用。我的语法可能不正确。
这是我的代码:
RedirectMatch 301 ^oldsite.com/guides/$ http://newsite.com/destinations/city-guides/
RedirectMatch 301 ^oldsite.com/show/$ http://newsite.com/tv-show/concept/
RedirectMatch 301 ^oldsite.com/destinations/$ http://newsite.com/tv-show/concept/
RedirectMatch 301 ^oldsite.com/concept.html http://newsite.com/tv-show/concept/
RedirectMatch 301 ^oldsite.com/format.html http://newsite.com/tv-show/format/
RedirectMatch 301 ^oldsite.com/about.html http://newsite.com/about/
RedirectMatch 301 ^oldsite.com/contact.html http://newsite.com/contact/
前三行我希望这些旧目录中的任何文件都转到新目录的根目录。最后四个是特定的页面到页面重定向。
我做错了什么?
您与
RedirectMatch
中的域名不匹配。仅匹配请求 URI。
在旧网站的.htaccess上试试这个:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www.)?oldsite.com$ [NC]
RewriteRule ^ - [L]
RewriteRule ^guides/$ http://newsite.com/destinations/city-guides/ [L,R=301]
RewriteRule ^show/$ http://newsite.com/tv-show/concept/ [L,R=301]
RewriteRule ^destinations/$ http://newsite.com/tv-show/concept/ [L,R=301]
RewriteRule ^concept.html http://newsite.com/tv-show/concept/ [L,R=301]
RewriteRule ^format.html http://newsite.com/tv-show/format/ [L,R=301]
RewriteRule ^about.html http://newsite.com/about/ [L,R=301]
RewriteRule ^contact.html http://newsite.com/contact/ [L,R=301]