Add a folder before every single file request using mod_rewrite?
I'm developing a site on a local server and a remote server. While in development, the server has be in url.com/~user while on my localhost in development I am simply developing in root. ie if I include a file on the local se开发者_运维问答rver I simply refer to "/img/img.png" for example... while this is obviously going to return a 404 on the remote server as it would be looking for "/~user/img/img.png".
This is the same issue that was answered over @ Problems with pointing to files on local server versus remote however what I am wondering here is if this can be solved with mod_rewrite? Defining SITE_ROOT works within the php files... but it doesn't fix the files being referred to in the CSS sheets.
Is it possible to simply tell my remote server to add /~user/ to every single file inclusion? ie a /img/img.png becomes /~user/img/img.png ?
Thanks for any pointers.
I'm going to take a guess that you are on some kind of shared server in production. The problem with your situation is that something like http://example.com/img/some.jpg will generate a request that (without special setup) will not hit .htaccess in the web directory in http://example.com/~user/. So, unless you have access to the server-wide apache config, this won't work for you.
What you could do if you want to go this route is write the URLs as /~user/img/some.jpg. You could do a rewrite on your development server, then, to get rid of the ~user.
Better yet, why include the leading slash at all? That way, you get just img/some.jpg, which will be a relative path then. If you are referencing the image in http://localhost/index.html, it will pull http://localhost/img/some.jpg. If you are referencing the image in http://example.com/~user/index.html, it will pull http://example.com/~user/img/some.jpg.
Finally, what about just having a ~user directory on your development server so it's the same in both places?
精彩评论