.htaccess Code to Redirect a Website to New Domain

Sometimes we need to redirect our complete Website or Webpages to another URL or New Domain; reason can be anything as:

  • Website (URL) is in google penalty
  • Web-site or Webpage has been deleted from server and you get the broken webpage error 404.
  • Need to redirect your olddomain.com to www.newdomain.com
  • You are re-designing your Web-site url structure

Then you can perform the redirection by doing some changes in .htaccess file. .htaccess code to redirect complete website all pages to new domain home page by using htaccess redirect 301:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://www.new-domain.com/? [R=301,L]

With the help of above code user can redirect a complete website to another URL. And you can also redirect the individual webpages to new pages by using below code :

Redirect 301 /old-page.html https://www.domain.com/new-page.html

 

301 redirect all pages to one page

Use below .htaccess code to redirect all website pages to a folder or a page on same server/domain

Suppose you are having a forum https://www.domain/forum/ having more than 200 pages cached. Now you want to remove forum and would like to redirect all pages of forum to https://www.domain/forum/ or https://www.domain/, then below code will work for you.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteRule \/.+ /corruptmdfrepair/ [L,R]

online chat
SEOCLICK Company India SEOCLICK » htacess Redirect Website to New Domain
Internet Marketing Services
Website Design & Development
Careers @ SEOCLICK