0

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.

carlaa123
  • 45
  • 1
  • 7
  • "The 301 redirect only work on main domain." - Where is this 301 redirect you speak of? – MrWhite Jan 29 '22 at 11:08
  • Ok. So there is no mod_rewrite that can accomplish what i am looking for? The 301 redirect is setup on the host ( Cloudways ) and not in .htaccess. What i am looking for is to also redirect sub olddomain.com/example to newdomain.com/example – carlaa123 Jan 29 '22 at 13:25
  • "also redirect sub olddomain.com/example" - what is the "sub" referring to? A subdomain? – MrWhite Jan 29 '22 at 13:49
  • "So there is no mod_rewrite that can accomplish what i am looking for?" - Yes, of course there is, what makes you say that? I was just querying where your existing 301 is implemented. Why does this not already redirect everything to the new domain and preserve the URL (this is arguably easier than just redirecting the homepage). Although where "in the host" is this redirect configured? You will likely need to remove this, depending on how it is configured. – MrWhite Jan 29 '22 at 13:57

2 Answers2

1

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.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • Thank you for the reply and help:) – carlaa123 Jan 29 '22 at 19:11
  • I ended up ussing following rewrite: RewriteEngine On RewriteCond %{HTTP_HOST} ^olddomain.no$ [OR] RewriteCond %{HTTP_HOST} ^www.olddomain.no$ RewriteRule (.*)$ https://www.newdomain.no/$1 [R=301,L] – carlaa123 Jan 29 '22 at 19:12
0

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>
carlaa123
  • 45
  • 1
  • 7