Forum Moderators: phranque
I normally use /images for example to denote a directory. On the new host the links work when the domain name has propagated (I have other domains I created there) but when accessing by serverIP/~user/ they don't. The path to the index file is /user/public_html, but the server is interpreting the slash as the user directory only.
I want to be able to see this site is operational before pointing the nameservers at the new host.
I can get around the problem by using ./images instead. I don't want to do a find and replace on the code, so is there a way to write a mod_rewrite rule to get around this temporarily?
No takers, huh? :(
This should be fixable, but it's important to nail things down...
1) You request [serverIP...] and expect to receive the image file located at /user/public_html/images/some_image.jpg, but instead it is trying to serve
/user/images/some_iamge.jpg and failing. Is this description correct?
2) Where do you want to handle the problem - In httpd.conf, or in .htaccess? If .htaccess, in which directory will the .htaccess file be located in the filepath?
3) How many other subdirectories (like /images) do you have? (This might affect which approach is more convenient.)
Jim
You request [serverIP...] and expect to receive the image file located at /user/public_html/images/some_image.jpg, but instead it is trying to serve
/user/images/some_iamge.jpg and failing. Is this description correct?
Yes! Exactly. There are a few other subdirectories too.
I think I have to use .htaccess, httpd.conf is not an option on shared servers, is it?
I already have a .htaccess file in public_html which the server seems to be picking up ok (parsing my htm for includes, not that it can find them!).
On a shared server that you don't have administrative access to, httpd.conf is not an option.
Placed in /user/.htaccess, this should fix your images:
RewriteRule ^images/(.*) /user_public/images/$1 [L]
I don't want to suggest a more-flexible (and more complex) approach that would rewrite several directories for a couple of reasons: One is that the liklihood of rewriting more URLs than you intend is high, and the other is that you said (I believe) that this is a temporary fix until you make the switchover, and the new DNS resolves. So, simple is better.
For more info, see this handy Introduction to mod_rewrite [webmasterworld.com].
Jim
I have misled you a bit Jim - I thought the paths were as you interpreted them but apparently not.
The broken links to pictures have properties of [serverIP...] Even if i create a dummy folder of images in the /user directory (one above public_html), the server still can't find it (with no rewrites in place).
So it appears the server can't find directories or files without a './' in the HTML path, rather than a '/'. My host tells me this is a quirk of the system when trying to use the site prior to domain propagation, and when I access my current host the same way I can recreate the problem.
I guess I will have to just upload the site and keep my fingers crossed or else do a find and replace on all the links and change them to './'.
Thanks for the rewrite tips, and the article that you gurus put together ;).
I'm going to guess your host is using name based hosting.
If this is the case, they could have any number of domains hosted using that IP. Calling it by IP/directory would not work in that case as the web server would have no clue which domain is should pull up the directory under. Calling it by domain would obviously work fine (after the domain propated).
There are ways around this (which your host would have to set up) or you could get a host which offers unique IP addresses.
Host doesn't seem to be too worried about my dilemma - no-one but me is worried about looking at sites prior to domain propagation I guess. I should have faith that my site will transfer ok but I like to check things 100%.
Go to your 'hosts' file, in W2K it is in WinNT/system32/drivers/etc/. Open with notepad. Create a new line with:
serverIP www.yourdomain.com (ensure space between IP and host)
Save file. Turn off any DNS proxies (modem routers etc.). Type host name into browser and Ctrl+Refresh to clear browser cache.
New site will appear! What this does is force local DNS for that domain, very useful before propagation.