Solved

reference files using both local and server-side virtual paths

Posted on 2014-09-18
2
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

626 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