Solved

reference files using both local and server-side virtual paths

Posted on 2014-09-18
2
197 Views
Last Modified: 2014-09-24
I am building a new website which has URLs such as:
http://www.domain.com/abc.htm

Then I have URL rewriting running on the server, which translates a URL such as:
http://www.domain.com/abc

...into the above one (with the .htm at the end).

I also have a CSS reference like this:
<link rel="stylesheet" href="css/main.css">

Open in new window


But that did not work with the URL rewriter, because the browser thinks it is in a subdirectory and therefore does not find the CSS file, so I changed it to:
<link rel="stylesheet" href="/css/main.css">

Open in new window


That seems to work. So far, so good.

However, I am doing most of my development locally on a Mac using MAMP and CodeKit. So my local test URL looks like this:
http://brads-macbook-pro.local:5757/domain.com/abc.htm

Using that, my "/css/main.css" reference does not work, because it is looking here:
http://brads-macbook-pro.local:5757/css/main.css

...rather than here:
http://brads-macbook-pro.local:5757/domain.com/css/main.css

So one method works locally, the other works on the server, but neither works on both.

One solution might be to upgrade to MAMP PRO, which I believe would allow me to create full virtual websites locally, thereby getting rid of the longer local URL structure (no sub-directory for domain.com). I have to verify this with MAMP PRO.

I'm wondering if there is any other solution I am not thinking of. Any advice?

Thanks!
0
Comment
Question by:bbdesign
2 Comments
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 40331974
I'm unfamiliar with Apache on Mac, but you're still going to have conf files for it.  One of those conf files is going to have the virtual host definition for the site you are building.  If you change that definition such that DocumentRoot points to the domain.com subdirectory, instead of its current location, that will resolve the issue.  This does mean, however, that anything in the upper-level directory will no longer be accessible by browsing - it is no longer in the document tree for the site.

You can find out where your conf files are by opening a terminal and running the apache executable with -S.  Depending on your installation, the name of the executable could be httpd, apache, apache2, or apache2ctl.  One of them will work - probably the last one.  Example:
[root@myserver:~]
#> apache2ctl -S
VirtualHost configuration:
1.2.3.4:80       www.site1.com (/etc/apache2/sites-enabled/site1.com.conf:4)
1.2.3.4:443      www.site1.com (/etc/apache2/sites-enabled/site1.com.conf:29)
5.6.7.8:80       www.site2.com (/etc/apache2/sites-enabled/site2.com.conf:4)
5.6.7.8:443      www.site2.com (/etc/apache2/sites-enabled/site2.com.conf:29)

Open in new window

In that example, the conf file I would want to change is /etc/apache2/sites-enable/site1.com.conf (or maybe site2.com.conf).
0
 

Author Comment

by:bbdesign
ID: 40342293
Thanks for your help. This told me what I needed to know, which was that it is not doable using my current configuration. I did upgrade to MAMP PRO and now I can setup local DNS which is working out well so far. Thanks again!
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question