Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So I'm pretty sure this question has been asked before, but I simply cannot find the answer by Googling - feel free to point me to the right site/post to look up the answer. Apologies for my poor search-fu... :(

I am developing a PHP application on Windows with WAMP. This needs to be deployed to a UNIX web host. The application will ultimately live on its own domain, e.g. www.example.com but I am developing it on my WAMP server under localhost/app1, i.e. I have multiple applications I'm working on, each one lives in its own directory.

My problem is that I am referring to shared resources by their absolute paths, e.g. /images/test.jpg. Their of course works fine on my production server, but when I try to use this on my local machine, it fails to load those resources because I'm running from within a "subdirectory" in WAMP, i.e. localhost/app1/, so the link to /images/test.jpg fails. It should instead be mapped to localhost/app1/images/test.jpg.

I've tried putting a

RewriteBase /app1/

directive in my .htaccess in the /xxx/app1 directory, but that merely results in an error:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace/

The certainly makes sense, since now every call to localhost/app1/ redirects to localhost/app1/, etc.

So, my question is: how should I set up my application so that I can run the same code on localhost with WAMP as well as on my production host? I realize I may have been barking up the wrong tree here and should be structuring this completely differently, so any pointers in the right direction in this regard would be most appreciated!

Thanks in advance!

share|improve this question

2 Answers 2

up vote 0 down vote accepted

See this SO question and read up on RewriteBase to make sure you understand it. I would just use a regular rewrite rule(s) at the server level:

RewriteEngine On
RewriteRule ^/images(.*) /app/images$1  

The mod_rewrite page has more details and examples if needed. The downside of this approach is having to have multiple rules to rewrite everything needed in which case you can try something like:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !/app
RewriteRule ^/(.*) /app/$1  

If you have issues with the rewriting rules (like I often do) you can temporarily enable the RewriteLog for debugging purposes. Another potentially useful item is the HTML <BASE> tag which is sometimes easier to use.

share|improve this answer
    
Thanks uesp, that helped! –  HerbCSO Jun 5 '11 at 12:11

The application will ultimately live on its own domain, e.g. www.example.com but I am developing it on my WAMP server under localhost/app1, i.e.

There is your problem!

The way I develop on Windows (using WampDeveloper Pro) is I either:

A. Use the same exact domain name and enable Local DNS for the website (Windows host file resolve of domain to 127.0.0.1).

B. Use a config.inc.php file for my website which uses a variable or constant to define the domain-name as dev.example.com, and on production as www.example.com. And also define any full paths.

Hence this issue completely goes away.

share|improve this answer
    
This is a good idea, too. Thanks for the suggestion! –  HerbCSO Jun 5 '11 at 12:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.