简体   繁体   中英

CodeIgniter on subdomain and htaccess

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM