.htaccess将所有流量重定向到域,但很少有手写异常

时间:2015-02-07 10:15:43

标签: .htaccess

如何将流量从www.old.com重定向到www.new.com,但

  • www.old.com/hellowww.new.com/byebye
  • www.old.com/test?start=5www.new.com/page/site

我从头开始:

RewriteEngine On
RewriteBase /

# root
RewriteCond %{HTTP_HOST} ^www\.(([^\.]+))\.pl [NC]
RewriteRule ^(.*)$ http://%1.pl%{REQUEST_URI} [R=301,L]

# Redirect
Redirect permanent old.com/hello new.com/byebye

1 个答案:

答案 0 :(得分:0)

您可以使用此.htaccess:

RewriteEngine On
RewriteBase /

# redirect
RewriteCond %{HTTP_HOST} ^www\.old\.com$ [NC]
RewriteRule ^hello$ http://www.new.com/byebye [NC,R=301,L]
RewriteCond %{HTTP_HOST} ^www\.old\.com$ [NC]
RewriteCond %{QUERY_STRING} ^start=5$ [NC]
RewriteRule ^test$ http://www.new.com/page/site? [NC,R=301,L]

# root
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.pl [NC]
RewriteRule ^ http://%1.pl%{REQUEST_URI} [R=301,L]