dorich Posted March 21, 2011 Share Posted March 21, 2011 Since google only offers their "preferred url" feature on a root domains they suggest that you do a 301 redirect in the .htaccess file to handle the preferred domain. I've searched around and can't find a tutorial that deals specifically with only redirecting for a subdomain, most examples seem to focus on just handling URLs at the root level. In my case my preferred url will be http://tools.example.com I assume therefore that I have to redirect http://www.example.com/tools to the preferred url? Searching the web suggests the following code is close to what I want: >Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^example\.com RewriteRule (.*) http://example.com/$1 [R=301,L] For the subdomain rewrite does this code become: > Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^example\.com\tools RewriteRule (.*) http://tools.example.com/$1 [R=301,L] My assumption is that the above code, or the correct version of it, is inserted into the .htaccess file at the end - ie no additional code is needed. The subdomain and the root domain are both running Wordpress blogs. I'd appreciate any pointers to detailed reference material, or direct answers, on how to tackle this problem so that I can be sure I've got the code correct. Thanks. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted March 21, 2011 Share Posted March 21, 2011 If you are unable to access your subdomain as http://tools.example.com here's a little tip. Rename the "tools" folder something else temporarily. Then go into cPanel and create a subdomain called "tools". Once cPanel creates the subdomain rename the "tools" folder it creates to something else. Now rename your original "tools" folder back to what it was. Launch your browser using the preferred URL and your subdomain should load. Once it's working you can delete the folder you renamed that cPanel created. I take it you probably used Fantastico to install Wordpress in your "tools" folder. Quote Link to comment Share on other sites More sharing options...
dorich Posted March 22, 2011 Author Share Posted March 22, 2011 If you are unable to access your subdomain as http://tools.example.com here's a little tip. Rename the "tools" folder something else temporarily. Then go into cPanel and create a subdomain called "tools". Once cPanel creates the subdomain rename the "tools" folder it creates to something else. Now rename your original "tools" folder back to what it was. Launch your browser using the preferred URL and your subdomain should load. Once it's working you can delete the folder you renamed that cPanel created. I take it you probably used Fantastico to install Wordpress in your "tools" folder. @ TCH - Bruce Thanks for your response. My apologies but I miscommunicated. My question is not about accessing the subdomain - at least I don't think it is. My question is: "do I have the correct code for redirecting" The reason is that google is "suggesting" that a user define a "preferred URL" so that when google crawls the site they (google) don't repeat the content for different versions of what is essentially the same domain. In my case a bad result would be that google crawls the site for tools/example.com and then crawls it as example.com/tools. For root domains google lets you specify your preferred url. However, if you have a subdomain the option is not available and so they suggest a 301 redirect. Apologies if my explanations are vague but I just learning this part and I'm still fuzzy. With regard to your last point I manually installed both Wordpress sites. Any pointers on the redirect question would be appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted March 22, 2011 Share Posted March 22, 2011 Yes, your redirect would be correct >Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^example\.com\tools RewriteRule (.*) http://tools.example.com/$1 [R=301,L] Quote Link to comment Share on other sites More sharing options...
dorich Posted March 22, 2011 Author Share Posted March 22, 2011 Yes, your redirect would be correct >Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^example\.com\tools RewriteRule (.*) http://tools.example.com/$1 [R=301,L] Thanks, very much appreciated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.