Page is a not externally linkable
jdMorgan - 3:14 pm on Mar 21, 2008 (gmt 0)
In example.com/.htaccess: You really have three choices here, and you should think about what you want to do. If you get a request for example.com/addon/ or addon.example.com, you can: The code above shows one example for each of the first two choices in the list. The choices you make will depend on whether or not your addon-domain folders have already been "exposed" to search engines, and how well you test your sites. Obviously, you don't want to return 403-Forbidden unless the folder paths have never been published, and you are sure that you will never link to them accidentally. All-in all, I think I prefer the rule "If an incorrect URL mentions "addon", correct it by redirecting to addon.com". The trailing-slash problem may or may not be corrected by the modified rules above. If it is not corrected, then that means that it is a problem in the server configuration code used to rewrite addon domains to addon folders, and your host will have to fix that. Jim
In /addon_folder/.htaccess:
RewriteEngine on
#Redirect to example.com if request was made to www.addon.example.com or addon.example.com
RewriteCond %{HTTP_HOST} ^(www\.)?addon\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
# If [i]direct client request[/i] for www.example.com/addon or example.com/addon, redirect back to addon domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /addon/?
RewriteRule ^addon/?(.*)$ http://addon.com/$1 [R=301,L]
Checking THE_REQUEST ensures that /addon was directly requested by the client, and is not the result of the internal rewrite used to map addon.example.com to /addon. If the request was direct, we want to redirect it. If the request was the result of the internal rewrite, we do not want to redirect it, because that would break the addon subdomain.
Brought to you by WebmasterWorld: http://www.webmasterworld.com