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:
And the permalinks also seem to use to www subdomain:
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/example-post
-> 301
with location which will redirect again to
due to the
.htaccess
config). Also, all guids inside the database do not contain the www.
Is there a way to prevent these unnecessary redirects? My SEO analysis tool is complaining about redirection chains.
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:
And the permalinks also seem to use to www subdomain:
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.
Is there a way to prevent these unnecessary redirects? My SEO analysis tool is complaining about redirection chains.
Share Improve this question edited Mar 8, 2022 at 11:17 DurandA asked Mar 8, 2022 at 11:08 DurandADurandA 1012 bronze badges1 Answer
Reset to default 1Settings 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.