Forum Moderators: phranque

Message Too Old, No Replies

Accessing website by IP but client side absolute paths are messed up!?

Using /ServerIP/~account/ before transfer of domain name - to test site 1st

         

penders

9:40 am on Sep 7, 2006 (gmt 0)

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



Hi, I have shared-hosting on Apache. I have created a new account, uploaded the website files and need to test it fully before transfering the domain name, which is currently pointing to a live site elsewhere.

I access the site using:
http://SERVER-IP/~account/

The problem is that the website (as far as the client side HTML/CSS is concerned) is contained within an /~account/ subdirectory, so my absolute paths in my CSS/HTML are now 1 directory too high up the tree. This is particulary effecting my CSS:

background-image:url(/img/banner.jpg);

This would work fine if the proper domain name was being used, but not with the SERVER-IP/~account/ format. As a result I am not seeing my background images!

It is tricky to avoid absolute paths in the CSS file if the CSS file is used throughout the site, from files at different levels in the tree.

How do I reliably test the site without the domain name?

Is there any work-around for this? Use of .htaccess perhaps? I assume this is an Apache server issue?

Any help greatly appreciated, cheers.

jdMorgan

7:19 pm on Sep 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use mod_rewrite to add the ~path to all requested URLs that do not already contain that path element.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

penders

7:33 am on Sep 8, 2006 (gmt 0)

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



Many thanks for the pointers.

camani

9:49 pm on Sep 15, 2006 (gmt 0)

10+ Year Member



I have the same problem as penders ... and have searched high and low for the answer.

Specifically I want to test a site move before point my domain to it. The test url root is myhost.com/~mysite. The problem if I understand it right is the tilde (~). The root resolves to the host.

I'm very new to mod_rewrite, but willing to learn. I've read many tutorials to try to solve this.

My question (forgive me if this is too obvious for you) is if I can really rewrite a URL request, if the server believes the root is myhost.com. When I place the the .htaccess in myhost.com/~mysite - does it even see it? I realize if I had better understanding of mod_rewrite I would probably know the answer, but it is overwhelming to understand when starting from scratch.

I tried replacing "/" with "/~mysite" with no effect. I learned later that you can only do that in the httpd.conf, not in .htaccess (which makes sense).

If someone can point to a post or article that deals with this (specifically for testing sites with root-relative links), it would be *greatly* appreciated!

jdMorgan

11:50 pm on Sep 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code would have to go into myhost.com.

You might look into using a subdomain for testing, as this avoids having to rewrite anything, and many hosts don't charge you for subdomains.

Jim

camani

12:16 am on Sep 16, 2006 (gmt 0)

10+ Year Member



Thank you for that answer, will save me hours in trial and error testing.

I'll check into the sub-domain idea.

Chris

camani

2:34 pm on Sep 20, 2006 (gmt 0)

10+ Year Member



I finally resoved this issue by setting up a new test domain name to be used for test purposes. This lets me test all scripts, stylesheets etc. Once I am satisfied the site is working correctly, I will point the real domain name to the site.

Since domain names are inexpensive these days, it works. My host allows for extra "domain pointers" to use additional domains at no charge, which I can set up myself.

Once the real domain name resolves to the site, I can use the subdomain idea for testing, using a subfolder as a test root.

I gave up trying to redirect or change to root directory. As far as I can tell, on a shared server I have no way to do this.

Regarding mod_rewrite, I wrote

I tried replacing "/" with "/~mysite" with no effect.

I meant
replacing "/" with "/~mysite/"
though I actually tried both to no avail, because as Jim pointed out, the htaccess would have to go in the "root directory" which I can't get to.

I supposed the problem was the tilde (~) in the path, but more correctly, I guess until a domain name resolves to my account, my files are seen to be in a subfolder of the host. (myhost.com/~mysite)

By the same token, a subdomain is not effective until I actually have a domain.

Thanks for the tips. Hope this helps someone.

sonjay

8:20 pm on Sep 20, 2006 (gmt 0)

10+ Year Member



What I'll often do in a situation like that is simply edit my hosts file (on my local machine) to point the domain to the IP address of the new server. That in essence makes your computer not do a dns lookup of the domain, and just request the site directly from the server at the specific IP address. So long as the new host server has the site configured properly, it'll serve up the site just like any other. Root-relative paths work, scripting that depends on the server name or document root work, everything works just as if you had already changed the dns.

When you want to go to the old site, you can simply comment that line out of your hosts file. No restart or reboot required.

If you have clients who need to view the site on the new server, though, that's not such a good solution, because clients (at least mine) are generally not capable of editing their hosts file.