0

I'm trying to setup a website based on CodeIgniter. For developing I want to have the domain dev.XXX.com

I changed my structure so I've got a no_www and a public_www folder. Both are in the root of dev.XXX.com

So my idea was to rewrite url's form

dev.XXX.com/index.php/test

to

dev.XXX.com/public_www/index.php/test

So I just want add public_www to all the requests

In my htaccess file I've got:

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

But I always get 500 - Internal Server Error

1
  • So you want to keep your index.php? Commented Feb 8, 2012 at 17:23

1 Answer 1

5

Try adding the following to the .htaccess file in the root directory (public_www) of your site.

RewriteEngine on RewriteBase / #if its on dev.xxx.com RewriteCond %{HTTP_HOST} ^dev\.XXX\.com$ [NC] #if its not already public_www/ rewrite to public_www/ RewriteRule ^(?!public_www/)(.*)$ /public_www/$1 [L,NC] 

The rule you had would lead to an infinite rewrite and subsequent 500 error. The one above should prevent that.

EDIT

could you maybe explain why my version leads into a infinite loop

I am likely incorrect about the infinite loop, but below is what will happen

  1. Start with any input
  2. ^(.*)$ pattern will match any input
  3. It will rewrite to /public_www/$1
  4. .htaccess rules will be run again
  5. ^(.*)$ pattern will match rewritten input /public_www/$1
  6. It will rewrite to /public_www/public_www/$1
  7. At this point it will likely fail as the directory does not exist...

Your RewriteRule pattern ^(.*)$ will match all input and will rewrite to . The .htaccess rules will then be run again

Sign up to request clarification or add additional context in comments.

9 Comments

could you maybe explain why my version leads into a infinite loop?
right now my .htaccess file is in my document root / under the root I've got the no_www and the public_www folder when I replace my htaccess with yours nothing happens when I create a new .htaccess in my public_www folder as you said I still get Error 500 when accessing the public_www folder
@skelle the .htaccess should be in the DocumentRoot. Can you give me full URL that you tested with
doesn't the L mean LAST? so I thought he stops after this rule I will post an public URL in some minutes
Ulrich, +1 on the explanation -- except that it will be an unbounded iteration failing on Max redirects. My only quibble is that IIRC if you look at the rewrite.log for this type of replacement, it is usually safer to drop the leading / on relative targets in Per Dir processing (e.g. .htaccess files) -- less potential bizarre side-effects.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.