Forum Moderators: phranque

Message Too Old, No Replies

Change root directory with .htaccess?

         

gizmotoy

1:21 am on Jun 13, 2008 (gmt 0)

10+ Year Member



My longtime host has decided to close shop, which left me transitioning to a new host. I have everything transferred over, but I have a problem verifying the site is up and running.

You see, until I switch my domain name over I need to temporarily access my site using the direct path from my host's domain name (hostdomain/~username/).

Unfortunately, this breaks my site as references to root now go to the host's main site instead of the my own site (/mypicture.jpg becomes hostdomain/mypicture.jpg instead of hostdomain/~username/mypicture.jpg).

Is there a way I can change something temporarily, by .htaccess perhaps, in order to test the site before I start sending accesses from my domain name there?

It seems like this would be a common problem, but I've searched everywhere and have had no luck whatsoever. I'm at a complete loss. Any suggestions would be appreciated.

jdMorgan

1:48 am on Jun 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you need to test your site before going live, get an IP-address-based virtual server, not a name-based virtual server. Such a set-up, where your hostname has its own unique IP address, often costs as little as $1 extra per month. It has the added advantage that you can point any domain (and any number of domains and subdomains) you like to your IP address.

I'm afraid that .htaccess cannot help in this situation, because the .htaccess file would have to reside at hostname.com/.htaccess, and shared access at that level would make all accounts quite insecure.

Jim

gizmotoy

2:03 am on Jun 13, 2008 (gmt 0)

10+ Year Member



That's what I was afraid of. I should have seen this coming. Unfortunately my new host does not offer such a setup. I guess my only option is to just start sending traffic there and try to fix the site once it's live. Yuck.

Thanks for the help, though.

encyclo

2:06 am on Jun 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



.htaccess won't help, but you can add an entry in your local machine's
hosts
file for your domain with the new IP address. That will enable you to test your site on the new server prior to changing the DNS.

gizmotoy

2:11 am on Jun 13, 2008 (gmt 0)

10+ Year Member



That would work if I had a dedicated IP address, which I unfortunately do not. I send a message to my host asking for one temporarily. I doubt they'll do it, but I don't see another way.

g1smd

2:22 am on Jun 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I guard against this by making all of the pages link to an include file that states the domain name in a variable. That variable is then used in the site navigation links all over the site, and in the base tag.

The "PHP include path" is defined in the .htaccess file and this makes the site totally portable to a new host and domain. It also allows testing on a localhost machine, either as localhost or as a fake "test" domain name forced through the HOSTS file on the PC.

For any non-canonical domain, a meta robots noindex,nofollow tag is forced for all pages, and GA code is also suppressed by a couple of lines of PHP in a common "include" file.

encyclo

7:14 pm on Jun 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That would work if I had a dedicated IP address, which I unfortunately do not.

For name-based virtual hosting, you can just set up a hosts entry for your domain and the shared IP address of the new server. No need for a dedicated IP address.

gizmotoy

8:06 pm on Jun 13, 2008 (gmt 0)

10+ Year Member



That doesn't seem to work. I get a 404 when I try to browse to simply the IP address. Even IP/~username/ gives a 404. They must be doing something weird.

They also said no to a temporary private IP. I may have to try to get my money back and go with someone else.

encyclo

2:25 pm on Jun 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps I haven't explained clearly enough - assuming the site is set up at the new host as a name-based virtual host, the shared IP address for the server is 10.11.12.13, and your site is www.example.com. In your hosts file, add an entry like this:

10.11.12.13 www.example.com

Your hosts file is found at

c:\windows\system32\drivers\etc\hosts
if you are running XP - open the file in notepad.

Then you can access your site on the new server by using your usual domain name. Just comment out the hosts file entry when you need to access the site at on the old server.

gizmotoy

3:20 pm on Jun 14, 2008 (gmt 0)

10+ Year Member



Sure, and I did it just like that, but for some reason it didn't work. It was giving a really weird 404 that just consisted of the text "404" and nothing else. I don't know what kind of setup they're using.

I did however, come up with a solution. I have a second domain that's currently unused, so I just parked it at the new host. The DNS servers updated overnight and I was able to verify that everything is working.

Thanks for all the help and suggestions. You guys are great.