Frage

I am constantly finding myself a situation where I work on my clients' projects locally and put projects in appropriately-named folders. However, on production the files are put into root. I use absolute paths starting with a forward-slash to access all assets as such:

<img src="/images/picture.jpg" />

This works fine in production environment, but in development this translates to the root folder where all my projects are, so I would naturally have to include the folder name in the source above, which really breaks the flow of work:

<img src="/project/images/picture.jpg" />

I have read up about RewriteBase, but that seems to address htaccess rewrite rules only. There is also a tag that could go into the HEAD section of the doc, but that does not seem to work too well with the front-coming forward slash. I would prefer to keep that forward-slash. Also, might be important to note, that my CSS files follow the same path logic.

Does anyone have a solution to my issue? Thanks.

War es hilfreich?

Lösung

As I've understood your question you are accessing your projects like http://localhost/project1/, http://localhost/project2/, ...

Create a virtual host for every project.

If your project is www.example.com you would create a virtual host (on your development machine) local.example.com which resolves to 127.0.0.1.

Andere Tipps

I use to run into the same issue, but what I did was just start placing the files I am working on in the root and when I'm done on that project move it into its proper folder. Then do the same for the next project. That way I am always coding for root to match my PROD environments.

The .htaccess you spoke of you would a pain because for each new folder you would have to go in and save it again.

Even jQuery wont be able to assist because your pathing your CSS sheets in the same manor.

It might be a few additional steps to always work in root, but at least your able to deploy the code without any find/replace.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top