Do Google sitemap URLs need to be double urlencoded
?
I am submitting my sitemaps to Google and Google is having difficulty navigating to URLs that contain urlencoded
characters. An example of a problematic URL is one that contains here&there
(which has been urlencoded
to here%26there
). In my sitemap, this URL looks like this:
example.com/here%26there
However, Google misreads my sitemap and searches for:
example.com/here&there
which returns a 404 error. Do I need to double encode the URL in my sitemap so that it looks like this:
example.com/here%2526there
(note that %
becomes %25
)
Although this question is about Google and the way it reads sitemaps ((do Google sitemap URLs need to be double urlencoded
)), I'll go ahead and show you guys the code I'm using to double encode my URLs for my sitemaps:
for($j = 1; $j <= $page_count; $j += 1){
$data .= '<url><loc>'.str_replace('%', '%25',
BASE_URL.'products/'.
urlencode(str_replace('/', '~1', $list['manufacturer']))).
($j == 1?'':'/'.$j).'</loc></url>'.PHP_EOL;
}
Note that non-URL '/'s are completely removed and all other special characters are double encoded.
preg_replace
you can handle characters such as&
(it would be recommended to handle these in the URL's as well, even if replacing them with a hyphen or something).