Redirect all urls exactly, just change domain name

前端 未结 3 699
野性不改
野性不改 2021-01-01 19:15

I have a website with roughly 1K URLs. The website is moving to a different domain name. The URLs will be the exact same though, otherwise. I\'d like to incorporate an htacc

相关标签:
3条回答
  • 2021-01-01 19:21

    Place this rule in your DOCUMENT_ROOT/.htaccess file of domain.com:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC]
    RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]
    
    0 讨论(0)
  • 2021-01-01 19:40

    When moving a domain name to a new domain where the only change to the url is the domain name, I use the following redirect in my Apache .htaccess file

      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
      RewriteCond %{HTTP_HOST} ^www.domain.com$
      RewriteRule ^(.*)$ http://newdomain.com$1 [R=301,L]
    

    This ensures that all links in the old site are redirected and search engines like Google, Bing etc. are aware that the domain was permanently moved. This has the benefit that any ranking from domain.com is transferred to newdomain.com. Make sure not to include a / after the domain in the rewrite rule or it will double-up.

    This is an alternative to the method shown above.

    0 讨论(0)
  • 2021-01-01 19:45

    With www or without

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} (w*)domain\.com$ [NC]
    RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]
    
    0 讨论(0)
提交回复
热议问题