0

I recently migrated a website which was both hosted with and without www subdomain. I configured the .htaccess to always redirect to www:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Also the site address is now configured to use www:

hostname_conf

And the permalinks also seem to use to www subdomain:

permalinks

However, if I configure a slug for a page as bellow and try to access the page using the post name, the server will send a 301 redirect (GET www.example.com/example-post -> 301 with location https://example.com/example-slug which will redirect again to https://www.example.com/example-slug due to the .htaccess config). Also, all guids inside the database do not contain the www.

slug

Is there a way to prevent these unnecessary redirects? My SEO analysis tool is complaining about redirection chains.

1 Answer 1

1

Settings in .htaccess tell the server how to handle requests. Since the site previously allowed both www and non-www URLs, you'll want to keep your .htaccess in place, so old links redirect properly. However, that doesn't tell WP that it's now living in the www subdomain; it stores URLs in many places.

You can ignore the GUIDs - they're just unique IDs - but you can run a search and replace script or plugin to update all the other URLs in the database.

If you have WP CLI enabled, the command is

wp search-replace 'https://example.com' 'https://www.example.com'

If not, there are also database migration plugins available that will update all the URLs and re-serialize them properly in the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.