Forum Moderators: phranque
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L] The files for this primary site are found in the root folder. However, when I attempt to do the same thing for any of the other sites, I run into problems. I assume it is because these other websites are inside separate folders within the root folder. For example, the files for myothersite.com would be in the folder "myothersite". Thus, when I alter the .htaccess file and try to visit myothersite.com, I get redirected to www.myothersite.com/myothersite/ rather than the desired www.myothersite.com. Can someone please show me what the following should look like so I can get myothersite.com to redirect to www.myothersite.com given my situation?
RewriteCond %{HTTP_HOST} ^myothersite\.com$ [NC]
RewriteRule ^(.*)$ http://www.myothersite.com/$1 [R=301,L] [edited by: jdMorgan at 1:37 am (utc) on Feb. 19, 2009]
[edit reason] de-linked [/edit]
RewriteCond %{HTTP_HOST} ^myothersite\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.myothersite\.com(\.¦\.?:[0-9]+) [NC]
RewriteRule ^(myothersite/)?(.*)$ http://www.myothersite.com/[b]$2[/b] [R=301,L]
If it's not clear, the following hostnames are perfectly-valid, but non-canonical:
myothersite.com
myothersite.com.
myothersite.com:80
myothersite.com.:80
www.myothersite.com.
www.myothersite.com:80
www.myothersite.com.:80
All seven will be corrected by the code above.
Important: Replace the broken pipe "¦" character in the second RewriteCond pattern with a solid pipe character before use; Posting in this forum modifies the pipe characters.
The basic problem is/was likely that GD is internally rewriting your myothersite.com domain to the filepath /myothersite *before* transferring control to your .htaccess file. Your code then does an external redirect, thus "exposing" the /myothersite internal file-path to the requesting HTTP clients (e.g. search robots and browsers).
This problem can occur even in a stand-alone .htaccess file, and this is why we recommend ordering your code with all external redirects first, in order from most-specific pattern (affects fewest URLs) to least-specific pattern (catch-alls affecting more URLs), followed by internal rewrites, again from most-specific to least-specific.
Jim