For Netbeans users only: How do you handle multiple web roots?

When I create a new Netbeans project, it's Properties > Source section of the dialog box will show my web root. For example, when I create an application called 'myApp', NetBeans Properties dialog box would show:

Project Folder: C:\xampp\htdocs\myApp
Source Folder: C:\xampp\htdocs\myApp
Web Root: <Source Folder>

Let's say that C:\xampp\htdocs\myApp has a _css subfolder where I store my CSS files. When I try to provide an ABSOLUTE path in my page like this:

<link rel="stylesheet" href="/_css/main.css" />

Netbeans reports an error:

Failed to load resource: the server responded with a status of 404 (Not Found) (10:41:10:815 | error, network)
  at http://localhost/_css/main.css

Notice above that Apache now thinks my web root is C:/xampp/htdocs instead of C:/xampp/htdocs/myApp. In other words, the '/' somehow is pointing to C:/xampp/htdocs instead of the web root I specified in Netbeans (which is C:/xampp/htdocs/myApp).

Has anyone encountered this problem? And if so, how does a Netbean user make the '/' correctly point to the application web root? Someone has suggested altering the Apache configuration files to point to the appropriate application root, but that would throw off all other applications I create under C:/xampp/htdocs.

Thanks.
elepilAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
The problem is that when you run your project is not Netbeans but Apache which interprets values in your head links. In other words, if you use an absolute path, Apache will use its own document root not the Netbeans one, so it will look for your css folder within http://localhost instead of within http://localhost/myApp.
Netbeans doesn't affects nor changes Apache config values and in effect the only way it would be to make your app folder the Apache document root, but obviously this would compromise any other your application.
I never found this problem because I use my local server very rarely. Usually I create a subdomain on my server and I set my project as a remote project (http://www.experts-exchange.com/Programming/Editors_IDEs/VP_573.html). This way you'll can use absolute paths without problems because in your remote server the '/' will works as expected. In your local server you'll always would have to add your application folder: '/myApp/css/...' but this would force you to change the code before to upload it to the remote server.
So, finally, I suggest you to use only relative paths if you want to work on your local server or to use the Netbeans feature to use remote server to develop and test your applications.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
To Marco Gasi.

Thanks for responding.

All you've described makes absolute sense to me, but I was hoping there would be a way to make Netbeans "compensate" the URL. Otherwise, it would make no sense to make one Apache installation per application on one's local server and then alter the Apache config's document root.

The problem with using relative paths is that it causes me problem when I use mod_rewrite because the "path point of reference" can change, depending on how I rewrite my URL. I was hoping there would be a way in Netbeans' configuration to "compensate" the URL based on the web root the user had specified.

While it is tempting to do all my development on the remote server, it is ideal to me to be able to code in my local server at times, but your comments make me seriously reconsider my way of doing things.

I'll leave this post open for a short while longer to get feedback from other Netbeans users. But thanks for your response, Marco.
elepilAuthor Commented:
Thanks for your help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.