복붙노트

codeigniter의 경로에서 "index.php"를 제거하는 법

PHP

codeigniter의 경로에서 "index.php"를 제거하는 법

센터의 codeigniter에있는 모든 경로에서 "index.php"를 제거하려면 어떻게해야합니까? 나는 깨끗한 비 index.php - fied URL을 원합니까?

해결법

  1. ==============================

    1.Apache를 사용하는 경우 다음을 포함하는 루트 웹 디렉토리에서 .htaccess 파일을 배치하십시오.

    Apache를 사용하는 경우 다음을 포함하는 루트 웹 디렉토리에서 .htaccess 파일을 배치하십시오.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    다른 좋은 버전은 여기에 있습니다.

    http://snipplr.com/view/5966/codeigniter-htaccess/

  2. ==============================

    2.index.php를 제거하는 데 큰 문제가있었습니다. 일반적으로 아래의 .htaccess는 여러 서버에서 테스트되었으며 일반적으로 작동합니다.

    index.php를 제거하는 데 큰 문제가있었습니다. 일반적으로 아래의 .htaccess는 여러 서버에서 테스트되었으며 일반적으로 작동합니다.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]  
    
    <Files "index.php">
    AcceptPathInfo On
    </Files>  
    

    운이 없다면 다음 단계는 설정 파일을 조정하는 것입니다. 다른 URI 프로토콜 중 일부를 사용해보십시오.

    | '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']  = 'ORIG_PATH_INFO';
    

    행운이 없다고해도 하위 폴더를 포함하도록 다시 쓰기 규칙을 변경하십시오. 이것은 dev 서버 등에서 임시 URL을 사용하는 경우 종종 문제가됩니다.

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

    이 옵션들로 놀아 라. 또한 색인 파일이 다음으로 설정되어 있는지 확인하십시오.

    $config['index_page'] = '';
    

    행운을 빕니다!

  3. ==============================

    3.index.php 파일과 함께 응용 프로그램 루트 디렉토리에 .htaccess 파일이 있어야합니다. (htaccess 확장자가 올바른지 확인하십시오. Bt htaccess.txt가 작동하지 않습니다.)

    index.php 파일과 함께 응용 프로그램 루트 디렉토리에 .htaccess 파일이 있어야합니다. (htaccess 확장자가 올바른지 확인하십시오. Bt htaccess.txt가 작동하지 않습니다.)

    그리고 다음 규칙을 .htaccess 파일에 추가합니다.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]  
    

    그런 다음 application / config / config.php 파일에서 다음 줄을 찾으십시오.

    $config['index_page'] = 'index.php';
    

    빈 변수를 아래와 같이 설정하십시오.

    $config['index_page'] = '';
    

    그것이 그 것이고, 그것은 나를 위해 일했습니다.

    작동하지 않으면 다음 변수를 이러한 매개 변수 ( 'AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI'및 'ORIG_PATH_INFO')로 차례로 교체하십시오.

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

    4.system \ application \ config \ config.php 파일을 살펴보면 index_page라는 변수가 있습니다.

    system \ application \ config \ config.php 파일을 살펴보면 index_page라는 변수가 있습니다.

    이렇게 보일 것입니다.

    $config['index_page'] = "index.php";
    

    그것을

    $config['index_page'] = "";
    

    그런 다음 언급 한 바와 같이 .htaccess 파일에 다시 쓰기 규칙을 추가해야합니다.

    참고 : CodeIgniter v2에서이 파일은 system 폴더에서 application \ config \ config.php로 이동되었습니다.

  5. ==============================

    5.위의 모든 방법이 실패하고 AllowOverride None을 / etc / apache2 / sites-available / default의 가상 호스트 파일에있는 AllowOverride로 변경하지 않는다는 것을 알았습니다.

    위의 모든 방법이 실패하고 AllowOverride None을 / etc / apache2 / sites-available / default의 가상 호스트 파일에있는 AllowOverride로 변경하지 않는다는 것을 알았습니다.

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
    
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride All    <---- replace None with All
        </Directory>
        <Directory /var/www >
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All   <---  replace None with All
                Order allow,deny
                allow from all
        </Directory>
    
         ...
    

  6. ==============================

    6.

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* /codeigniter/index.php/$0 [PT,L]
    
  7. ==============================

    7.그냥 내가 추가 할 수있을 거라 생각 했어.

    그냥 내가 추가 할 수있을 거라 생각 했어.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
    

    .htaccess이고 다음과 같은 방법으로 application / config.php 변수를 편집해야합니다.

    바꾸다

    $config['uri_protocol'] = “AUTO” 
    

    $config['uri_protocol'] = “REQUEST_URI”
    
  8. ==============================

    8.

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 
    

    이것은 분명히 작동해야합니다 .. 시도해보십시오

  9. ==============================

    9.

    RewriteEngine on
    RewriteBase    /project/
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /project/index.php/$1 [L]
    
    RewriteEngine on
    RewriteBase    /
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
  10. ==============================

    10.

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 
    
  11. ==============================

    11.내 CI 프로젝트 중 하나 인 .htaccess입니다.

    내 CI 프로젝트 중 하나 인 .htaccess입니다.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
    RewriteRule ^(.*)$ /projectFolder/index.php/$1 [L] 
    

    마지막 줄은 필요한 것을 제공해야하지만 폴더 구조 설정 방법에 따라 '/ projectFolder'가 필요할 수도 있고 필요하지 않을 수도 있습니다. 행운을 빕니다!

  12. ==============================

    12.CI wiki에서이 튜토리얼의 지시대로 mod_rewrite를 사용하십시오.

    CI wiki에서이 튜토리얼의 지시대로 mod_rewrite를 사용하십시오.

  13. ==============================

    13.mod_rewrite를 활성화했는지 확인하십시오. 사용하려면:

    mod_rewrite를 활성화했는지 확인하십시오. 사용하려면:

    sudo a2enmod rewrite  
    

    또한 AllowOverride를 AllowOverride로 대체하지 않음

    sudo gedit /etc/apache2/sites-available/default  
    

    결승전 ...

    sudo /etc/init.d/apache2 restart  
    

    내 .htaccess는

    RewriteEngine on  
    RewriteCond $1 !^(index\.php|[assets/css/js/img]|robots\.txt)  
    RewriteRule ^(.*)$ index.php/$1 [L]  
    
  14. ==============================

    14.\ application \ config \ config.php 파일을 보면 index_page라는 변수가 있습니다.

    \ application \ config \ config.php 파일을 보면 index_page라는 변수가 있습니다.

    이렇게 보일 것입니다.

    $config['index_page'] = "index.php";
    

    그것을

    $config['index_page'] = "";
    

    그런 다음 언급 한 바와 같이 다음과 같이 .htaccess 파일에 다시 쓰기 규칙을 추가해야합니다.

    RewriteEngine on
    RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    그것은 나를 위해 일하고 희망도.

  15. ==============================

    15..htaccess 파일로 Kohana Framework에서 제공하는 것을 사용하는 것이 좋습니다.

    .htaccess 파일로 Kohana Framework에서 제공하는 것을 사용하는 것이 좋습니다.

    # Turn on URL rewriting
    RewriteEngine On
    
    # Installation directory
    RewriteBase /
    
    # Protect hidden files from being viewed
    <Files .*>
        Order Deny,Allow
        Deny From All
    </Files>
    
    # Protect application and system files from being viewed
    RewriteRule ^(?:application|system)\b.* index.php/$0 [L]
    
    # Allow any files or directories that exist to be displayed directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # Rewrite all other URLs to index.php/URL
    RewriteRule .* index.php/$0 [PT]
    

    그것은 잘 작동하는 htaccess입니다.

  16. ==============================

    16.codeigniter에 대한 URL 경로에서 index.php를 푸는 방법에는 두 가지가 있습니다.

    codeigniter에 대한 URL 경로에서 index.php를 푸는 방법에는 두 가지가 있습니다.

    1 : config / config.php에서 코드 변경 :

    $config['index_page'] = 'index.php';
    

    $config['index_page'] = '';
    

    2 : 생성되지 않은 경우 루트 경로에 .htaccess를 만듭니다. 다음 코드를 복사하십시오.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    </IfModule>
    

    저장하고 아파치 설정 rewrite_module을 체크 인하거나 mod_rewrite를 Enabled로 설정하십시오. (최선의 접근법)!

  17. ==============================

    17.나는 여러 다른 호스팅에서 apache2에서 이것을 테스트했으며 훌륭하게 작동합니다.

    나는 여러 다른 호스팅에서 apache2에서 이것을 테스트했으며 훌륭하게 작동합니다.

    이 htaccess 사용

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    phpinfo ()로 mod_rewirte를 활성화했는지 확인하십시오.

    config / config.php에서 다음과 같이하십시오.

    $config['index_url']    = '';
    |
    | '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';
    

    아직 작동하지 않는다면 $ config [ 'uri_protocol'] = 'AUTO'를 40/54 줄에있는 나열된 내부 application / config / config.php 파일 중 하나로 변경하십시오.

    때때로 나는 AUTO 대신에 REQUEST_URI를 사용하거나 goDaddy 호스팅을 위해 "QUERY_STRING"을 사용했다.

  18. ==============================

    18.Linux를 사용하고 있고 apache2 서버를 사용하고 있다면 .htaccess 파일의 변경 사항 옆에 apache2.conf 파일을 무시해야 할 수도 있습니다. /etc/apache2/apache2.conf에서 apache2 구성 파일을 찾으십시오.

    Linux를 사용하고 있고 apache2 서버를 사용하고 있다면 .htaccess 파일의 변경 사항 옆에 apache2.conf 파일을 무시해야 할 수도 있습니다. /etc/apache2/apache2.conf에서 apache2 구성 파일을 찾으십시오.

    디렉토리 검색 / var / www / AllowOverride 변경 없음 -> AllowOverride 모두

    <Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory
    
  19. ==============================

    19..htaccess 파일을 루트 웹 디렉토리에 두십시오.

    .htaccess 파일을 루트 웹 디렉토리에 두십시오.

    위의 사항이 충족되지 않으면 조정할 수 있습니다. 작동하지 않습니다. 일반적으로 시스템 폴더에 루트에 있어야합니다. 건배!

  20. ==============================

    20.나는 많은 해결책을 시도했으나 내가 생각해내는 것은 이것이다 :

    나는 많은 해결책을 시도했으나 내가 생각해내는 것은 이것이다 :

    DirectoryIndex index.php
    RewriteEngine on
    
    RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots  \.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
    

    이 iwill은 필요에 따라 URL에서 index.php를 제거합니다.

  21. ==============================

    21..htaccess 파일에서이 줄을 사용합니다. 나는 루트 폴더에 놓는다.

    .htaccess 파일에서이 줄을 사용합니다. 나는 루트 폴더에 놓는다.

    RewriteEngine on
    RewriteRule ^(application|system|\.svn) index.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
    

    그런 다음 http://example.com/controller/function/parameter에 액세스 할 수 있습니다.

    http://example.com/index.php/controller/function/parameter 대신

  22. ==============================

    22.이것은 당신을 도울 것입니다. 이 코드를 .htaccess 파일의 응용 프로그램 폴더에 붙여 넣으십시오.

    이것은 당신을 도울 것입니다. 이 코드를 .htaccess 파일의 응용 프로그램 폴더에 붙여 넣으십시오.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]  
    
    <Files "index.php">
    AcceptPathInfo On
    </Files>
    <IfModule mod_php5.c>
      php_value short_open_tag 1
    </IfModule>
    
  23. ==============================

    23.이 하나의 완벽한 마술 않았다 :

    이 하나의 완벽한 마술 않았다 :

    RewriteEngine on
    RewriteBase /
    # Hide the application and system directories by redirecting the request to index.php
    RewriteRule ^(application|system|\.svn) index.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
    

    희망이 도움이됩니다!

  24. ==============================

    24.안녕하세요,이 하나의 날 일했습니다.

    안녕하세요,이 하나의 날 일했습니다.

    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /folder/index.php?/$1 [L]
    

    이뿐 만 아니라

    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /folder/index.php?/$1 [L]
    

    여기서 codeigniter 응용 프로그램이 하위 도메인으로 호스팅되는 경우 폴더는 하위 폴더의 이름입니다. 예 : domainname / folder / index.php.

    희망은 당신을 위해 작동합니다. 감사.

  25. ==============================

    25..htaccess 파일의 다음 코드 붙여 넣기 복사

    .htaccess 파일의 다음 코드 붙여 넣기 복사

    RewriteEngine on
    Options -Indexes
    RewriteCond $1 !^(index\.php|assets|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    
  26. from https://stackoverflow.com/questions/1445385/how-to-remove-index-php-in-codeigniters-path by cc-by-sa and MIT license