我做SEO的公司已经改变了他们的域名。
我写了301次重写,将流量重定向到新域。到目前为止,我有3个更改的重写,其中有很多。当我完成所有操作时,将会有大约30次重写,这看起来有点傻!
是否有通配符我可以用来确保满足以下3个参数?
会是这样的......
(.*)example-old(.*)
= www.example-new.co.uk
和
(.*)example-old(.*)/(.*)
= www.example-new.co.uk/directory
以下代码对问题3进行了排序,但并不能解决所有问题。
如果我可以使用一小段代码,使用通配符,这将是完美的。
任何帮助,非常感谢!
# 301 --- http://example.co.uk => http://www.example-new.co.uk
RewriteCond %{HTTP_HOST} ^example\.co\.uk$
RewriteRule ^$ http://www.example-new.co.uk/? [L,R=301]
# 301 --- http://www.example.co.uk => http://www.example-new.co.uk
RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk$
RewriteRule ^$ http://www.example-new.co.uk/? [L,R=301]
# 301 --- http://example.com => http://www.example-new.co.uk
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^$ http://www.example-new.co.uk/? [L,R=301]
# 301 --- http://www.example.com => http://www.example-new.co.uk
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^$ http://www.example-new.co.uk/? [L,R=301]
答案 0 :(得分:9)
假设您没有其他子域名www
,那么如果.htaccess
的根目录不同,您可以在相关域的根目录上的example-new.co.uk
文件中使用此简单规则:
RewriteEngine On
# anything that is not equal to www.example-new.co.uk
RewriteCond %{HTTP_HOST} !^www\.example-new\.co\.uk$
# redirects to http://www.example-new.co.uk/anything
RewriteRule ^/?(.*)$ http://www.example-new.co.uk/$1 [R=301,L]
它会将任何非www.example-new.co.uk的内容重定向到新域的URL路径。
所以,如果我访问:
http://example-new.co.uk/new-league <<< no wwww
我将被重定向到:
http://www.example-new.co.uk/new-league
如果我访问:
http://www.example-new.com/new-league <<< ends with .com
http://www.example-old.co.uk/new-league <<< domain is different
http://example-old.co.uk/new-league <<< domain is different
所以上述3个也将重定向到:
http://www.example-new.co.uk/new-league