I am changing my website's URL to improve the SEO. The current sitemap contains URLs like this:
mysite/browse/1 /* 1 is the ID for fashion */ mysite/browse/2 /* 2 is the ID for real estate */
Now I have changed the URLs to the following format:
I have have the code ready to be released along with the new sitemap. If I release the new code, the old URLs would no longer be valid, ie:
mysite/browse/2 would return "404 - page not found".
I believe I have to release the code and submit the new sitemap to Google Search Console. But I believe it would take Google sometime before actually crawling the new sitemap, so during this time, all my old urls which appear in the search result would return "404 - page not found" error.
How can I mitigate this situation?
You must redirect 301 each old url to its new value. For example If using IIS 7 or higher, the simplest solution is to use the httpRedirect element in your web.config.
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Permanent"> <add wildcard="/browse/1" destination="/browse/fashion" /> <add wildcard="/browse/2" destination="/browse/real-estate" /> </httpRedirect>
Adapted the source from this Answer: https://stackoverflow.com/a/13828044/3623080 but I'm not familiar with IIS and you may have to look further to adapt to your case.
And on Apache server in your
<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^browse/1$ /browse/fashion [R=301,L] RewriteRule ^browse/2$ /browse/real-estate[R=301,L] </IfModule>
So that old pages wont lead to 404 and Google will quickly replace URLs in SERP.
And of course you will be able to release your code and new sitemap without error nor seo loss.