Home > other >  301 Redirect, new domain
301 Redirect, new domain

Time:01-30

I have changed domain name on my website and having problem with setting up redirection.

The 301 redirect only work on main domain. olddomain.com to nydoamin.com

How do i setup redirections on the whole site? The link structure is the same. Example: olddomain.com/info/ to newdomain.com/info ?

My .htaccess is today:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I am using cloudways and have set newdomain as primary-domain and olddomain to additional domain.

CodePudding user response:

In the document root of the olddomain you can do something like the following using mod_rewrite at the top of the .htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]
RewriteRule ^ https://olddomain.com%{REQUEST_URI} [R=301,L]

NB: Test first with a 302 (temporary) redirect to avoid potential caching issues. You will likely need to clear your browser (and any intermediary) caches before testing.

CodePudding user response:

Thank you for the reply and help:) I ended up with using following:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ https://www.newdomain.com/$1 [R=301,L]
</IfModule>
  •  Tags:  
  • Related