Skip to content

Instantly share code, notes, and snippets.

@bavington
Last active July 22, 2020 15:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bavington/5982551 to your computer and use it in GitHub Desktop.
Save bavington/5982551 to your computer and use it in GitHub Desktop.
.htaccess rewrite code to use when 301'ing to a new domain name whilst maintaining the same URL paths.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.newdomain\.co.uk
RewriteRule (.*) http://www.newdomain.co.uk/$1 [R=301,L]
@gabrielizalo
Copy link

gabrielizalo commented May 9, 2016

Hello,
It don't redirects if the Old Domain is with HTTPS.
:(

@phdiegues
Copy link

phdiegues commented Apr 23, 2018

Hello @gabrieizalo for redirect with HTTPS use:

RewriteEngine on
RewriteCond %{HTTPS_HOST} !^www.newdomain.com
RewriteRule (.*) https://newdomain.com/$1 [R=301,L]

@swasthya
Copy link

RewriteEngine on
RewriteCond %{HTTPS_HOST} !^www.newdomain.com
RewriteRule (.*) https://newdomain.com/$1 [R=301,L]

perfectly working ...

if I want to only one folder www.olddomain.com/backoffice and its sub folders NOT to redirect and stay there

how to do it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment