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

Ulrich Palha
  • 9,411
  • 3
  • 25
  • 31
soupdiver
  • 3,504
  • 9
  • 40
  • 68

1 Answers1

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

Ulrich Palha
  • 9,411
  • 3
  • 25
  • 31
  • could you maybe explain why my version leads into a infinite loop? – soupdiver Feb 08 '12 at 17:55
  • 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 – soupdiver Feb 08 '12 at 18:04
  • @skelle the .htaccess should be in the `DocumentRoot`. Can you give me full URL that you tested with – Ulrich Palha Feb 08 '12 at 18:09
  • doesn't the L mean LAST? so I thought he stops after this rule I will post an public URL in some minutes – soupdiver Feb 08 '12 at 18:14
  • @skelle `L` does mean last and will stop processing rules further down, but there are cases e.g. when you rewrite to a directory that the rules need to be run again, from the start, see #1 in http://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite-rules – Ulrich Palha Feb 08 '12 at 18:19
  • 1
    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. – TerryE Feb 08 '12 at 19:13
  • did it again from scratch... fine working now :) thanks! can you also tell me how to change the file that requests to dev.xxx.com/index.php will be rewritten to dev.xxx.com/public_www/index.php (should happen with all files) – soupdiver Feb 08 '12 at 21:28
  • @skelle I don't understand what you are asking - can you give me more detail e.g. do you mean this does not work for index.php? – Ulrich Palha Feb 08 '12 at 22:24
  • it is working fine with the index.php but when I've got links to dev.xxx.com/index.php/foo ALL stuff like this should be rewritten to dev.xxx.com/public_www/index.php but I want to hide the public_www from the user in the url bar – soupdiver Feb 09 '12 at 12:26