Cybercampbell
Cybercampbell

Reputation: 2606

Best way to manage redirects

I need to have a temporary redirect setup and I just want to know the best way to go. I've looked into .htaccess, php, meta and contributed Drupal modules (this is with a Drupal 8 site) and I don't know which is the way to go.

It is a little complicated and yes I know, not ideal but I need this setup for the next 3 months while I build my new website. I'm just not ready for that to switch over just yet.

This is what I need to do:

www.myNewDomain.com -> www.myOldDomain.com

www.myNewDomain.com/sub1 -> www.myNewDomain.com/sub1

www.myNewDomain.com/sub2 -> www.myNewDomain.com/sub2

In other words, anything to the main domain only (no sub directory) gets bumped back to the old site URL.

But my subpages (micro-sites) go through as normal on the new site.

This is what I have so far using .htaccess:

RewriteCond %{HTTP_HOST} ^(www\.)?myNewDomain\.com [NC]
RewriteRule ^/?$ http://myOldDomain.com/ [L,R=301]

Any advise is very much appreciated.

Upvotes: 0

Views: 45

Answers (1)

pjmorse
pjmorse

Reputation: 9304

You don't actually need mod_rewrite to do this.

You want a simple redirect just for a URI of / with nothing following it; everything else isn't redirected.

Try this (I haven't):

RedirectMatch ^/$ http://myOldDomain.com/

Upvotes: 2

Related Questions