Forum Moderators: phranque

Message Too Old, No Replies

Redirect shared hosting full path to www.mysite.com?

Users can also access my site using the full hosting path

         

MrWumpus

12:01 am on Sep 9, 2009 (gmt 0)

10+ Year Member



I know how to use .htaccess to redirect a non-www to a www. but how do I use it in cases where my site can be accessed from an entirely different URL such as the literal server path URL on my shared host?

For example, my site is accessible from my regular www.mysiteurl.com but also from here:

webhostserver1.webhostname.net/~myusername/

If someone gets there using the above URL I want them directed to automatically redirect to www.mysiteurl.com.

As a rule, I always ask first before messing with .HTACCESS. Learned my lesson a few times already. ;)

jdMorgan

4:19 am on Sep 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The most-recommended solution, posted many times here in this forum, is to use 'negative logic' to solve the "www" problem, FQDN-format hostname requests, appended port numbers, and -- as a side benefit, cases like yours where the host has provided a "back-door" domain for you to use on a name-based shared hosting account when the 'real' domain has not yet been registered and/or the DNS has not yet been pointed to the server or has not yet propagated.

That is, if the requested hostname is NOT *exactly* your canonical hostname, then redirect the request to the canonical domain. No variation whatsoever in the canonical hostname should be allowed -- the match should be exact.

Jim

MrWumpus

5:38 am on Sep 9, 2009 (gmt 0)

10+ Year Member



Thanks, that makes sense now. I was able to search and find an example that forced the redirect in all cases.