从子域到root:最好的方法? [关闭]

I am not asking for a technical solution, just a plain "what approach would you recommend" vis-a-vis SEO, crawlability and user experience.

Imagine I am selling pastry on my website (let's call it pastry.com). I would like people specifically searching for cakes on google to go to my subdomain "cake.pastry.com" (listed as such on Google).

But, since I don't want to maintain multiple subdomains, "cake.pastry.com" would actually redirect to "pastry.com#cake", so that this approach could also be used for cupcakes and muffins! "cupcake.pastry.com" redirects to "pastry.com#cupcake", etc.

What would be the best way to do this? Is it possible to keep "cake.pastry.com" in the address bar while users are actually redirected "pastry.com#cake"? Would this pose a UX problem? Also, will this subdomain bring any value? I.e., will people searching for cakes on google actually find the "cake.pastry.com" subdomain higher than the root domain (because of keyword density, specificity of content...)? Would I need a 301 or 302 redirect? Via PHP or .htaccess?

So please, any opinion is welcome! Thank you!

I cannot fully answer the SEO parts of this question. But as far as I know, it is no good idea to list a page with different domains at Google. Beside this, subdomains are not made for this purpose. At least I like addresses like http://pastry.com/cake much more than your examples.

The technical answer:

  1. You need an wildcard DNS record to map all subdomains to pastry.com
  2. You can rewrite with mod_rewrite

I've not tested this, but this is more an example to show how this might work:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.pastry\.com$
RewriteCond %{HTTP_HOST} !^pastry\.com$
RewriteCond %{HTTP_HOST} ([^\.]+)\.pastry\.com  [NC]
RewriteRule ^(.*)$ http://pastry.com/#%1 [NE,R=301,L]