views:

277

answers:

3

Hi all.

I am trying to deploy a php / codeigniter project to a shared hosting environment. Locally I am running MAMP and all my paths are referenced thus:-

background:transparent url(/img/myimj.jpg) left top no-repeat;

When I deploy the shared host, these links do not work and to resolve them I need to add "../". Changing all these references alone would be tiresome. but codeigniter paths are also affected and I want to understand how I can have the same mapping as my local instance of MAMP apache.

Not being well versed in apache, I do not know how to resolve this issue. I am using the root public_html folder that has been mapped to my user. Is it possible to use a rewrite rule in a .htaccess to do this?

Thanks for your time.

A: 

You could use a .htaccess rewrite rule that just directs all images/css/whatever to a specific directory.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /path/relative/to/web-root/

    RewriteRule /?([^/]+)\.css css/$1.css
    RewriteRule /?([^/]+)\.(jpe?g|png|gif) images/$1.$2
</IfModule>

This is assuming all your images are in a folder called images and all the style-sheets in a folder called css.

In this scenario, it would be best call the images and stylesheets in your code/css using an absolute path. That way images would be cached properly. Even tho the server redirects all the images to the same directory, the client would not see that. So if the same image was called using a relative path from two files in different positions of the tree, the client would see those as two different images and not cache it properly

Atli
Thanks for your response. Having checked on the server, mod_rewrite is not enabled :SThe account is of the virtual host type and in the cpanel, it defines public_html as the www root, but could it be that the root is actually the directory above, hence the issue of the urls not resolving?
donkeykong
A: 

If your "shared" environment means that you're sharing a DOCUMENT_ROOT, then you'll have to be careful with a .htaccess file - as this will be the .htaccess file for everyone. Otherwise if you have a Virtual host, then what would it take to upload you images into /path/to/document/root/img?

ChronoFish
Having tried every combination, After a bit of testing, absolute local paths on the shared host have to be referenced like so:-background:transparent (/~username/common/img/myimg.jpg);Is there anything I can do to make it like my local web server?:-background:transparent (/common/img/myimg.jpg);
donkeykong
Ah... so you're in "that" kind of shared environment. You may have to bite the bullet and make the changes. Especially since MOD_REWRITE is not available to you. Find a good search/replace editor.
ChronoFish
A: 

Thanks for your input on this.

Having got through to the web hosting company, I have since realized that the behavior of a virtual host differs if you do not have an ANAME pointing to it. On adding one the folder public_html is mapped as web root as it should be.

donkeykong