Configuring 301 redirects for second domain

Keywords: WordPress + NGINX + SSL - Google Cloud Platform - How to - Other

Description:
Hi,

I have tried to find the answer to this without success.

I have a site hosted using a wordpress install on Nginx in Google Cloud. It is SSL enabled.

This all works fine.

I have an old domain for the site that is currently being url redirected at the DNS level, which is configured at the domain name provider.

This also works fine for domain level redirects but there are pages that used to exist at the old domain which now redirect to the home page of the existing site. This is not what I want, because these pages exist on the new domain as new urls.

I believe that I need to configure the domain to point to the ip address of the hosting and then configure within the nginx config files the redirects eg

redirect all incoming requests that don’t match the new hostname, to the new hostname (this currently happens anyway)
But I also need to do page level url redirects as the old page urls and new ones are different.

I’m not sure how to do this, I am more familiar with configuring apache and using mod_rewrite or 301 redirects in an htaccess file. I’m not even sure which config file to edit.

Any links to documentation would be much appreciated.

Hi @bookings1 ,

Did you configure the domain for WordPress?

https://docs.bitnami.com/aws/faq/configuration/configure-custom-domain/

Regards,
Michiel

Hi Michael,

That documentation appears to be for wordpress multi site? I’m not running a multi-site installation.

To clarify I have currently got:

mywebsite.co.uk configured on the server itself (as well as in dns). This all works.

myoldwebsite co uk 301’d at the dns level to mywebsite co uk - this redirects everything from myoldwebsite co uk to mywebsite co uk

I want myoldwebsite co uk/oldpage.php to redirect to mywebsite co uk/mynewpage/

I believe to do that I need to

  • List item
    remove the dns level 301 and set to dns for myoldwebsite co uk to the ip address of the nginx install

  • List item
    configure the server so that any requests for myoldwebsite co uk redirect to mywebsite co uk otherwise both the old and new address will be indexed

  • List item

redirect at the page level to any new urls

it’s steps 2 and 3 above that I’m not sure how to achieve

Hi @bookings1 ,

We have this guide that explains how to redirect all requests to your new domain

https://docs.bitnami.com/google/apps/wordpress-pro/administration/use-single-domain-nginx/

However, if you want to customize it or redirect “old pages” to new ones, we suggest you check the official documentation of NGINX to redirect those requests.

Thanks

Thanks, that definitely sounds like the place I need to start. However, there is no bitnami.conf located in that directory.

In fact I did a find and it appears that there is no bitnami.conf located on the system. Does that make sense? There is an /opt/bitnami directory and also these config files:

wordpress-server-block.conf
wordpress-https-server-block.conf

should I make the changes in one of these files instead?

Hi @bookings1,

Yes, you can find more information here:

https://docs.bitnami.com/virtual-machine/apps/wordpress-pro/configuration/create-vhost-nginx/

Regards,
Michiel

Ok I’m not quite there, I thought I was but it turned out that I had edited the wrong instance of the server_blocks config files and they were actually doing anything.

I have now found the correct ones but making the changes there has undesirable effects.

Without making any changes (other than at the dns level) both the old url and new url now return the new website name in the browser.

Ie I changed the DNS redirect to be an A record on the old hostname, pointing to the ip address.
When I visit the old hostname it now redirects to the new host name. There must be something else within the server config doing this because if I edit the server block config file and add something like this:

 # add to HTTPS section
  if ($host != "example.com") {
      return 301 https://example.com$request_uri;
  }

I end up with a too many redirects error.

I have added a rewrite statement to the same file. This works for the new hostname with old url but not old hostname with old url. I believe this is because I need the 301 on the request uri as well?

Where else could that be configured? I have ssl configured using letsencrypt, could the redirects there (eg http to https, non www to www) conflict with the server block?

Hi @bookings1 ,

I recommend checking the official documentation of NGINX for this issue.

Regards,
Michiel

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.