当前位置: 动力学知识库 > 问答 > 编程问答 >

php - 301 Redirects Old Domain to New Domain

问题描述:

Im looking at moving domains for my site.

The first part of the url will change ie www.olddomain.co.uk to www.newdomain.co.uk. However the second part of the domain will stay the same.

Do I place my htaccess with the redirects on my old server or new server?

Thanks

网友答案:

I'm assuming by "second part" you mean the part of the URL after the domain, i.e. for http://www.somedomain.co.uk/index.php, the first part is http://www.somedomain.co.uk/ and the second is index.php.

You can redirect this using a mod_rewrite rule in your .htaccess on your old domain (assuming you have permission to do so and mod_rewrite is installed). Something like this should do the trick:

RewriteEngine on
RewriteRule   ^/(.+)$  http://www.newdomain.co.uk/$1  [R=301,L]

You could also use a RedirectMatch (supplied by mod_alias) if you don't have mod_rewrite:

RedirectMatch ^/(.*) http://www.newdomain.co.uk/$1

This should give you more information on mod_rewrite remapping: http://httpd.apache.org/docs/2.4/rewrite/remapping.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: