Solved

reference files using both local and server-side virtual paths

Posted on 2014-09-18
2
194 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now