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.

I want dev.test.com, to go to a specific directory, /var/www/cakephp/dev/webroot. Here's my apache2 conf file:

<VirtualHost *:80>
        ServerName dev.test.com
        Redirect permanent / /var/www/cakephp/dev/webroot
</VirtualHost>

I keep getting successive 301 Moved permanently responses (until the server stops sending them, or is it the browser stops requesting them?)

GET dev.test.com: http://dev.test.com/var/www/cakephp/dev/webroot
GET webroot: http://dev.test.com/var/www/cakephp/dev/webrootvar/www/cakephp/dev/webroot
GET webroot: http://dev.test.com/var/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webroot
[...] 21 requests later (seriously):
GET webroot: http://dev.test.com/var/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webrootvar/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot/

I found these responses via firebug. Anyone know what the problem could be? Thanks.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Instead of a Redirect, isn't what you need a DocumentRoot?

What you're doing here is sending a redirect back to the client. Therefore, what's happening is that Apache's prepending the name of the current VHost onto the redirect target string, and sending:

Location: http://dev.test.com/var/www/cakephp/dev/webroot

Of course, when that hits, it finds the dev.test.com VHost, and lo and behold! there's a Redirect in there that applies to this request. So it happily sends you to http://dev.test.com/var/www/cakephp/dev/webroot/(yourrequeststring), which works out to:

Location: http://dev.test.com/var/www/cakephp/dev/webroot/var/www/cakephp/dev/webroot

Make sense now? At any rate, what you need is:

<VirtualHost *:80>
    ServerName dev.test.com
    DocumentRoot /var/www/cakephp/dev/webroot
    <Directory /var/www/cakephp/dev/webroot>
        Order allow,deny
        Allow from all
        Deny from none
    </Directory>
</VirtualHost>

The section is optional; add it only if you get 403's when you try to use the site with the new DocumentRoot directive in place.

share|improve this answer
    
You are smart, my friend. Thanks! –  ash Jun 26 '10 at 3:33

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.