When I search for a relevant page (on my example.com domain) in Bing.Com, and click the URL that reads example.com/subfolder2/file.html it has this underlying long URL in Bing.Com:
https://www.bing.com/ck/a?!&&p= .... a very long random code ... &ntb=1
My server returns the missing.html identified in the root htaccess. This means old URLs in that search engine cache won't get fixed, and the user misses my content.
I have a .htaccess file on my root directory, and the intent is to do these things with permanent redirects
- move
example.com/subfolder/file.htmltosubfolder.example.com/file.html - move
example.comtowww.example.com - return "index.html" if there is no file specified
Mostly successfully, I am using this .htaccess code in the root directory of example.com:
ErrorDocument 403 http://www.example.com/missing.html
ErrorDocument 404 http://www.example.com/missing.html
ErrorDocument 500 http://www.example.com/missing.html
AddHandler server-parsed .html .htm .shtml .shtm
Options +FollowSymLinks -Indexes -MultiViews +Includes
DirectoryIndex index.html
RewriteEngine On
RewriteBase /
#move to subdomains
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^/?subfolder1/(.*)$ http://subfolder1.example.com/$1 [R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^/?subfolder2/(.*)$ http://subfolder2.example.com/$1 [R=301]
#if missing sub-domain, add "www"
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
As expected, the URL www.example.com/subfolder/file.html works, returning subfolder2.example.com/file.html. If I type example.com/subfolder/file.html on my browser, it also works.
What am I missing?
Noting: a) when I add htaccess code to the subfolder, it does nothing; b) I have 7 different subdomains, each with their own rewrite rule, not two, so I am sure I am missing some efficiency in writing or executing the rewrites; c) I have HTTP service from my server; d) the cached version on Bing reports as http://example.com/subfolder/file.html, and; e) I might have run into this same quirky result from a Google search, but it has either washed away or I can't replicate/recall exactly what happened.
Thanks !