2011-01-31 4 views
2

28 일에 발표 된 Codeigniter v2.0. 난 그냥 신선한 설치를 설치하고 URL에서 index.php를 제거하려고했습니다. 동일한 아파치 사이트 - 사용 가능한 구성, htaccess 및 codeigniter 구성을 사용하고 있습니다.codeigniter 2 htaccess 라우팅 차이점

Codeignter는 index.php를 제외 할 때 routes.php에 정의 된 기본 컨트롤러 만로드합니다. 예를 들어

  • 하지만 http://myurl.com/index.php/events이 이벤트 컨트롤러 여기
  • 를로드 환영 컨트롤러를로드 환영 컨트롤러

  • http://myurl.com/events을로드하면 내 아파치 구성
    • http://myurl.com/welcome입니다 문제의 사이트.

      <VirtualHost *:80> 
      ServerAdmin [email protected] 
      ServerName myurl.com 
      DocumentRoot /var/www/myurl.com 
      <Directory /> 
          Options FollowSymLinks 
          AllowOverride FileInfo 
      </Directory> 
      <Directory /var/www/myurl.com> 
          Options Indexes FollowSymLinks MultiViews 
          AllowOverride FileInfo 
          Order allow,deny 
          allow from all 
      </Directory> 
      
      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
      <Directory "/usr/lib/cgi-bin"> 
          AllowOverride None 
          Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
          Order allow,deny 
          Allow from all 
      </Directory> 
      
      ErrorLog /var/log/apache2/error.log 
      
      # Possible values include: debug, info, notice, warn, error, crit, 
      # alert, emerg. 
      LogLevel warn 
      
      CustomLog /var/log/apache2/access.log combined 
      
      Alias /doc/ "/usr/share/doc/" 
      <Directory "/usr/share/doc/"> 
          Options Indexes MultiViews FollowSymLinks 
          AllowOverride None 
          Order deny,allow 
          Deny from all 
          Allow from 127.0.0.0/255.0.0.0 ::1/128 
      </Directory> 
      

      여기 내 htaccess로 구성

      <IfModule mod_rewrite.c> 
      RewriteEngine On 
      RewriteBase/
      
      #Removes access to the system folder by users. 
      #Additionally this will allow you to create a System.php controller, 
      #previously this would not have been possible. 
      #'system' can be replaced if you have renamed your system folder. 
      RewriteCond %{REQUEST_URI} ^system.* 
      RewriteRule ^(.*)$ /index.php?/$1 [L] 
      
      #When your application folder isn't in the system folder 
      #This snippet prevents user access to the application folder 
      #Submitted by: Fabdrol 
      #Rename 'application' to your applications folder name. 
      RewriteCond %{REQUEST_URI} ^application.* 
      RewriteRule ^(.*)$ /index.php?/$1 [L] 
      
      #Checks to see if the user is attempting to access a valid file, 
      #such as an image or css document, if this isn't true it sends the 
      #request to index.php 
      RewriteCond %{REQUEST_FILENAME} !-f 
      RewriteCond %{REQUEST_FILENAME} !-d 
      RewriteRule ^(.*)$ index.php?/$1 [L] 
      
      </IfModule> 
      
      <IfModule !mod_rewrite.c> 
          # If we don't have mod_rewrite installed, all 404's 
          # can be sent to index.php, and everything works as normal. 
          # Submitted by: ElliotHaughin 
      
      ErrorDocument 404 /index.php 
      

      입니다 그리고 여기 내 CodeIgniter의 구성 파일이 /var/www/mysite.com/application/config/config을 발견합니다. PHP

      <?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
      
      /* 
      |-------------------------------------------------------------------------- 
      | Base Site URL 
      |-------------------------------------------------------------------------- 
      | 
      | URL to your CodeIgniter root. Typically this will be your base URL, 
      | WITH a trailing slash: 
      | 
      | http://example.com/ 
      | 
      | If this is not set then CodeIgniter will guess the protocol, domain and 
      | path to your installation. 
      | 
      */ 
      $config['base_url'] = 'mysite.com'; 
      
      /* 
      |-------------------------------------------------------------------------- 
      | Index File 
      |-------------------------------------------------------------------------- 
      | 
      | Typically this will be your index.php file, unless you've renamed it to 
      | something else. If you are using mod_rewrite to remove the page set this 
      | variable so that it is blank. 
      | 
      */ 
      $config['index_page'] = ''; 
      
      /* 
      |-------------------------------------------------------------------------- 
      | URI PROTOCOL 
      |-------------------------------------------------------------------------- 
      | 
      | This item determines which server global should be used to retrieve the 
      | URI string. The default setting of 'AUTO' works for most servers. 
      | If your links do not seem to work, try one of the other delicious flavors: 
      | 
      | 'AUTO'   Default - auto detects 
      | 'PATH_INFO'  Uses the PATH_INFO 
      | 'QUERY_STRING' Uses the QUERY_STRING 
      | 'REQUEST_URI'  Uses the REQUEST_URI 
      | 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO 
      
      */ 
          $config['uri_protocol'] = 'AUTO'; 
      
      /* 
      |-------------------------------------------------------------------------- 
      | URL suffix 
      |-------------------------------------------------------------------------- 
      | 
      | This option allows you to add a suffix to all URLs generated by CodeIgniter. 
      | For more information please see the user guide: 
      | 
      | http://codeigniter.com/user_guide/general/urls.html 
      */ 
      
      $config['url_suffix'] = ''; 
      
  • +0

    한다 RewriteRule에

    $config['uri_protocol'] = 'AUTO'; 

    ^(. *) $ /index.php/$1 [L] (당신의 물음표없이)? – Aif

    답변

    6

    라우팅 유형을 AUTO에서 REQUEST_URI로 변경하면 모든 것이 제대로 작동합니다.

    $config['uri_protocol'] = 'REQUEST_URI'; 
    
    +0

    uri_protocol에 관해서는 모든 호스트가 다르므로 URL에 뭔가 잘못되었다고 확신하고 그것이 .htaccess 규칙이 아니라는 것을 확신 할 때 나는 uri_protocol 값으로 주위를 어지럽히는 것이 좋습니다. AUTO가 일부 서버에서는 작동하지만 PATH_INFO 값은 대부분 다른 서버에서 작동하는 문제가있었습니다. –

    +1

    REQUEST_URI이 (가) 내 MAMP 로컬 호스트에 필요한 값입니다. 이전 버전의 CI와 다를 것으로 보입니다. ( – stef

    +1

    이전 CI 버전에서 uri_protocol을 AUTO로 설정하면 거의 자동으로 작동하므로 거의 모든 곳에서 작동 할 것입니다. 이제 테스트/프로덕션에서 다른 구성 값을 사용해야합니다. 서버. 그 편리하지 ... ... ( – janosrusiczki