Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

reference files using both local and server-side virtual paths

Posted on 2014-09-18
2
Medium Priority
?
201 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 2000 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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

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…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
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…
The viewer will learn how to count occurrences of each item in an array.

715 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