views:

26

answers:

2

I currently have css and javascript file calls (amongst other things) like the following:

href="/css/default.css" src="/js/ui_control.js"

putting the preceding / in to make the files relative to the root.

This works great when my page is in the root of the domain. However, I'm currently in the middle of transferring my site to a new hosting provider and as such have a temporary URL which is: HOST-IP/~username

As such, all file calls are trying to be called from HOST-IP/css/default.css etc instead of within the ~username sub-folder.

Of course I can wait until the domain name servers propagate but that's beside the point.

How would I go about writing a rule in the .htaccess file that would redirect all file calls that start with a /, from going to HOST-IP/FILE-CALL, and instead to go to HOST-IP/~USERNAME/FILE-CALL. ?

Any ideas?

A: 

I'd suggest changing the references in your HTML to the files to be relative, as this will work either in a sub folder or as the root of the domain.

Rowland Shaw
This isn't an option in most sites that use some sort of include file for templating.
ceejayoz
@ceejayoz It's the option I've used on all the sites I've ever worked on...
Rowland Shaw
i use includes, but also as i'm using url rewriting changing the ?p=pagename to /pagename, if I create a more detailed rewrite using virtual subfolders, then removing the slash will break the system. it must be all relative to the site's root, not the domain's root.
Gabriel
@Gabriel might be worth mentioning that in your question. If you're generating the content dynamically, you could still calculate the relative paths.
Rowland Shaw
blech, surely there's an easier option than writing php / js to fix it. I kind of figured this sort of thing would have been within the power of a .htaccess file.
Gabriel
A: 

This works great when my page is in the root of the domain. However, I'm currently in the middle of transferring my site to a new hosting provider and as such have a temporary URL which is: HOST-IP/~username

How would I go about writing a rule in the .htaccess file that would redirect all file calls that start with a /, from going to HOST-IP/FILE-CALL, and instead to go to HOST-IP/~USERNAME/FILE-CALL. ?

Unless you can put a .htaccess at HOST-IP/.htaccess on the new server, you can't do this with .htaccess. It sounds like you're on a shared host, so any approach that'd let you do this with .htaccess would allow you to hijack everyone else's site on the server.

ceejayoz