Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule for making Root-Relative URLs point to Subdirectory?

         

SomeGirl

6:36 am on Aug 8, 2010 (gmt 0)

10+ Year Member



It's been what feels like a million years since I've played with web technology, and I'm feeling lost.

I'm moving an already-established website to a new shared host (LiteSpeed). I have not yet pointed the domain to the new nameservers, as I'm still setting up stuff. I'd like to be able to look at the site on the new server to make sure everything I need is uploaded and not broken.

The pages use root-relative URLs and sources.
e.g.:
<link href="/layout.css" />
<img src="/_graphics/img.gif" />

Currently, because my domain is not yet pointing to the new space, my root directory is not www.mysite.com, but rather www.myhost.com/~myaccount/
Naturally, because of this, all of my links and sources are trying to access my files from www.myhost.com/ and failing.

Years ago, while doing a similar project, I seem to recall using a pretty simple site-wide code to accomplish this (I remember regretting it when I forgot to remove it when my site went live and Google started indexing my non-domain links) -- seems like classic mod_rewrite behavior, but I've searched and tried various things to no avail.

Either that, or it might be as simple as the HTML tag <base href="">, but for some reason I can't get that to work for me.

Can anyone help? I hope I've explained this clearly enough -- I'm bleary-eyed at this point.

Thanks!

g1smd

6:19 am on Aug 9, 2010 (gmt 0)

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



You need to put the code in the root folder of the site. Your host will not allow that.

If you did put the code there, all requests for
www.myhost.com/<anything>
would be rewritten to your folder, including all requests for all other sites hosted on that server.

There's no way to solve this problem using Mod_Rewrite.

In fact you should install the reverse of this code. You need a redirect such that if
www.myhost.com/~myaccount/<anything>
is requested, user is redirected to
www.example.com/<anything>
instead.

jdMorgan

3:34 pm on Aug 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Odd that <base href="http://www.myhost.com/~myaccount"> doesn't work here...

Consider switching to an IP-based virtual server instead of a name-based virtual server if this option is available. This gets rid of the "mod_userdir" problem, and allows you to use your server's IP address as its hostname for testing.

I pay an extra $1 a month for IP-based shared hosting, and it is well worth it in terms of testing, freedom to map additional domains to the server and to add as many subdomains as I like (such as "test.example.com"), and ability to access the site by IP address before DNS changes propagate or in case of DNS failures.

Other than that, it looks like global find-and-replace is the only remaining option... :(

Jim