views:

170

answers:

3

So I'm setting up SVN on my home server (Ubuntu 9.1), and want the ability to view any changes made to my CodeIgniter app immediately.

So, my working copy lives in /home/myname/environments/development/appname.

My Vhost is accessible at dev.appname.myname.ca, and the config looks like this:

 DocumentRoot /home/myname/environments/development/
 ServerName dev.myname.ca
 ServerAlias dev.*.myname.ca

 RewriteEngine On
 RewriteCond %{HTTP_HOST} !^www.* [NC]
 RewriteCond %{HTTP_HOST} ^dev.([^\.]+)\.myname\.ca
 RewriteCond /home/myname/environments/development/%1/trunk/ -d
 RewriteRule ^(.*) /%1/trunk/public/$1

So, going to dev.appname.myname.ca would point to /home/myname/environments/development/appname/trunk/public.

Now, this being a CodeIgniter app, I need to redirect all requests from public/ to public/index.php, so the .htaccess file in public/ is as follows:

RewriteEngine On
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]

I have this part in an .htaccess file because on a live production site, I won't have access to the server config so I'd need to override it.

The problem is now that I'm getting a loop of redirects and ultimately a 500 error.

From /var/log/apache2/error.log:

redirected from r->uri = /appname/trunk/public/index.php/appname/trunk/public/index.php/appname/trunk/public/index.php/appname/trunk/public/index.php/appname/trunk/public/index.php/appname/trunk/public/index.php/appname/trunk/public/index.php/

How can I redirect the request to the proper public/ directory (in this case, /home/myname/environments/development/appname/trunk/publc) and THEN direct all requests from public/ to public/index.php?

I know it's a long-winded question - thanks for your help. :)

A: 

Try using something a little less crazy, you should not need to redirect from public/ to public/index.php as Apache will do that for you.

The CodeIgniter Wiki shows how to create the ultimate CodeIgniter .htaccess.

Phil Sturgeon
A: 

AS Phil mentioned you should use the rewrite rules from here http://codeigniter.com/wiki/mod_rewrite/

For some debugging you can add following lines to your httpd.conf or virtual host conf.

<IfModule mod_rewrite.c>
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 3
</IfModule>

With

tail -f /var/log/apache2/rewrite.log

you can check the rewrite rules and some errors. You can also change the Level to 9. Take care with this option. It produce a lot of information. It's sometimes rely helpful.

DrDol
A: 

Your RewriteRule is backwards from what you actually want.

RewriteRule ^(.*)$ index.php/$1 [L]

This will turn "dirA/dirB/dirC/" into "index.php/dirA/dirB/dirC". On the subsequent HTTP request, this will satisfy the condition and the rule will be applied again. And again, and again...

Try:

RewriteRule ^(.*)\/?$ $1/index.php [L]
Eric Kolb
If you do that CodeIgniter will never work. The [L] flag means it will redirect to index.php then do no more re-directs.
Phil Sturgeon