Solved

reference files using both local and server-side virtual paths

Posted on 2014-09-18
2
195 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

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reset email that plugins send alerts to 1 35
Hovering effect 9 47
Reinstall Putty Windows 7 5 46
Windows and other UI names - The Proper names for the Various elements! 1 58
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

911 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

21 Experts available now in Live!

Get 1:1 Help Now