Home WordPress 301 redirect loop issue
Reply: 1

WordPress 301 redirect loop issue

user3256143
1#
user3256143 Published in 2018-01-13 12:44:29Z

I'm keeping an existing WordPress website but changing the domain name. The old domain name will be redirected to the same website, so if someone went to https://oldexample.com they would arrive at https://newexample.com.

From what I have read will need to do a 301 redirect from the old slugs to the new URLs, like this:

redirect 301 /old-page/ https://newexample.com/new-page

But in every article I've read online this approach assumes that the old slug is named something different to the slug.

But in my case, all of the pages have the same slug but will have a different domain. For example: A slug from the old domain might be my-cool-page and with the new domain there is also a page called my-cool-page, and according to what I've read I would need to do this:

redirect 301 /my-cool-page/ https://newexample.com/my-cool-page

But, and here is my question: Wouldn't this cause a redirect loop? Or can I simply get away with this:

redirect 301 https://oldexample.com/my-cool-page/ https://newexample.com/my-cool-page
yivi
2#
yivi Reply to 2018-01-13 12:50:40Z

The only rule you need in .htaccess is this:

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

This will cover all your URLs. The approach you were using would not only cause a redirection loop, but would need a new rule per each URL. Not very efficient.

Since it's Wordpress, and Wordpress saves URLs in the DB, you'll need to do a search & replace of the old domain in the DB and replace it with the new one.

There are many tools and/or plugins to do that. The best, IMO, is wp-cli. Using it you would just need to execute

wp search-replace https://oldexample.com https://newexample.com

from the command line, and you'd be ready to roll.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301927 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO