URL Change – Add Redirect to New Site

With a change of website URL to implement, the old domain was to be retained, with a 301 redirect added to the .htaccess file. Visitors would be redirected to the new URL.

Once the new website was proven then the files and database on the existing domain space can be archived.

Shown below is a redirect for the non https to the https, as configured in the .htaccess file.

<IfModule mod_rewrite.c>


  RewriteEngine On

  RewriteCond %{HTTPS} !=on


  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


</IfModule>


Taking this as the basis for my url redirect gave:

<IfModule mod_rewrite.c>
  
RewriteEngine On
  
RewriteCond %{HTTPS} !=on


  RewriteRule (.*) https://example.com%{REQUEST_URI} [R=301,L]
</IfModule>

I chose to add the above to the top of the .htaccess file. This can be processed prior to the other entries and its easy to spot subsequently.

After a suitable period of time, letting the subsequent testing and settling in of the change occur the next step is to remove the unneeded parts of the old website.

The files can be removed and a copy retained, or tucked in an impossibly named folder. and the elements of the .htaccess file which aren’t required can be removed, perhaps retaining security aspects.