복붙노트

CodeIgniter는 URL에서 index.php를 제거합니다.

PHP

CodeIgniter는 URL에서 index.php를 제거합니다.

현재 URL은 [mysite] index.php / [슬러그의 나머지 부분]처럼 보입니다. 나는이 URL에서 index.php를 제거하고 싶다.

mod_rewrite가 내 apache2 서버에서 사용 가능합니다. config에서 $ config [ 'index_page'] = '';

내 codeigniter 루트 .htaccess 파일에 포함되어 있습니다,

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

하지만 여전히 작동하지 않습니다. 내가 어디로 잘못 가고 있니?

해결법

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

    1.다음을 시도해보십시오.

    다음을 시도해보십시오.

    config.php를 열고 다음을 대체하십시오.

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

    $config['index_page'] = ""
    

    uri_protocol의 기본 설정이 제대로 작동하지 않는 경우도 있습니다. 그냥 바꾸십시오.

    $config['uri_protocol'] ="AUTO"
    

    으로

    $config['uri_protocol'] = "REQUEST_URI"
    

    .htaccess

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

    참고 : .htaccess 코드는 호스팅 서버에 따라 다릅니다. 일부 호스팅 서버 (예 : Godaddy)에서 추가 기능을 사용해야합니까? 위 코드의 마지막 줄에. 해당 행의 다음 행은 마지막 행으로 대체됩니다.

    // Replace last .htaccess line with this line
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 
    
  2. ==============================

    2.단계 : -1 "application / config"폴더를 열고 "config.php"파일을 엽니 다. config.php 파일에서 아래의 코드를 찾아서 바꿉니다.

    단계 : -1 "application / config"폴더를 열고 "config.php"파일을 엽니 다. config.php 파일에서 아래의 코드를 찾아서 바꿉니다.

    //find the below code   
    $config['index_page'] = "index.php" 
    //replace with the below code
    $config['index_page'] = ""
    

    단계 : -2 CodeIgniter 폴더로 이동하여 .htaccess를 만듭니다.

    Path:
    Your_website_folder/
    application/
    assets/
    system/
    .htaccess <——— this file
    index.php
    

    단계 : -3 .htaccess 파일에 코드 아래에 쓰기

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

    단계 : -4 uri_protocol의 기본 설정이 제대로 작동하지 않는 경우도 있습니다. 이 문제를 해결하려면 "application / config / config.php"파일을 열고 아래 코드를 찾아 교체하십시오

    //find the below code
    $config['uri_protocol'] = "AUTO"
    //replace with the below code
    $config['uri_protocol'] = "REQUEST_URI" 
    

    그게 전부지만 우리는 그것을 활성화해야합니다 기본적으로 비활성화 rewrite_module 때문에 wamp 서버에서 작동하지 않습니다. 이것을 위해 다음을 수행하십시오

    링크

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

    3.1 단계 :

    1 단계 :

    이것을 htaccess 파일에 추가하십시오.

    <IfModule mod_rewrite.c>
      RewriteEngine On
      #RewriteBase /
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.php [QSA,L]
    </IfModule>
    

    2 단계 :

    codeigniter config에서 index.php를 제거하십시오.

    $config['base_url'] = ''; 
    $config['index_page'] = '';
    

    3 단계 :

    Apache 구성에서 htaccess 무시 (명령)

    sudo nano /etc/apache2/apache2.conf
    

    파일을 편집하고 다음으로 변경하십시오.

    AllowOverride All
    

    www 폴더 용

    4 단계 :

    아파치 모드 재 작성 사용 (Command)

    sudo a2enmod rewrite
    

    5 단계 :

    Apache (명령)를 다시 시작하십시오.

    sudo /etc/init.d/apache2 restart
    
  4. ==============================

    4.

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

    용도

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

    site.com/index.php/class/method/id에 url이있는 경우

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

    5.

    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]
    
  6. ==============================

    6.두 단계가 있습니다.

    두 단계가 있습니다.

    1) config.php 수정

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

    $config['index_page'] = '’;
    

    2) .htaccess 파일 만들기 / 편집

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

    7.귀하의 htaccess에 이것을 사용하십시오,

    귀하의 htaccess에 이것을 사용하십시오,

    RewriteEngine On
    RewriteBase /root_folder_name/
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    희망이 도움이됩니다.

  8. ==============================

    8.config.php 파일에있는 index.php를 제거하십시오.

    config.php 파일에있는 index.php를 제거하십시오.

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

    9.이것을 시도해보십시오. 그것은 나를 위해 일하는 데 도움이 될 수 있습니다.

    이것을 시도해보십시오. 그것은 나를 위해 일하는 데 도움이 될 수 있습니다.

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

    코드를 루트 htaccess 파일에 넣으십시오.

    $config['index_page'] = '';
    

    설정 파일에.

    문제가 발생하면 알려주십시오.

  10. ==============================

    10.

    + Copy .htaccess from Application to Root folder
    + edit .htaccess and put
    
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /ci_test/
    
        #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
    </IfModule>
    
    Note: make sure your web server is enable for  "rewrite_module"
    
    + Remove index.php from $config['index_page'] = 'index.php';
    - edit config.php in application/config
    - search for index.php
    change it from  $config['index_page'] = 'index.php'; to  $config['index_page'] = '';
    

    참조 용으로이 비디오를 시청하십시오. https://www.youtube.com/watch?v=HFG2nMDn35Q

  11. ==============================

    11.우선 아파치 서버에 엔진을 다시 작성해야합니다.이 링크는 당신을 위해 도움이 될 것입니다.

    우선 아파치 서버에 엔진을 다시 작성해야합니다.이 링크는 당신을 위해 도움이 될 것입니다.

    http://www.anmsaiful.net/blog/php/enable-apache-rewrite-module.html

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

    .htaccess 파일이됩니다. 지금 해봐.이 설정은 나를 위해 작동합니다.

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

    12.

      Removing index.php from url of codeigniter   
    
    Three steps are require to remove index.php from url in Codeigniter.
    
    1)Create .htacess file in parallel to application holder and just copy past the following code:
    
    RewriteEngine On
    RewriteBase /CodeIgniter/
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
    2) Change $config['index_page'] to blank in config.php in application folder as below:
    
    $config['index_page'] = '';
    
    3) Enable “rewrite_module” of apache.
    
  13. ==============================

    13.개발과 생산 모두

    개발과 생산 모두

        # Development
        RewriteEngine On
        RewriteBase /your_local_folder/
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
        RewriteRule ^(.*)$ index.php/$1 [L]
    
        #Production PHP5 CGI mode
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
        RewriteRule ^(.*)$ index.php?/$1 [L]
    
  14. ==============================

    14.1. 루트 디렉토리에서 .htaccess 파일을 새로 작성하십시오.

    1. 루트 디렉토리에서 .htaccess 파일을 새로 작성하십시오.

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

    2. config.php 파일로 가서 $ config [ 'index_page'] = 'index.php'에서 $ config [ 'index_page'] = ''로 변경하십시오.

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

    15.config \ config.php 파일로 이동하여이 변수에서 index.php 값을 제거 할 수 있습니다.

    config \ config.php 파일로 이동하여이 변수에서 index.php 값을 제거 할 수 있습니다.

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

    .htaccess 파일을 만들고이 코드를 붙여 넣으십시오.

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

    좋은 기회

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

    16.나는 모든 설정이 좋다고 생각하지만 htaccess 파일을 잘못 놓으려고하면 htaccess를 프로젝트 파일에 추가하십시오.

    나는 모든 설정이 좋다고 생각하지만 htaccess 파일을 잘못 놓으려고하면 htaccess를 프로젝트 파일에 추가하십시오.

    project_folder-> htaccess

    htaccess에이 코드를 추가하십시오.

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

    17.글쎄,이 모든 대답은 좋지만 초보자에게는 (처음하는 것은) 혼란 스럽습니다. 컨트롤러에 상주하는 다른 htaccess 파일이 있지만 기본 프로젝트 폴더에서 htaccess를 편집하거나 추가해야합니다.

    글쎄,이 모든 대답은 좋지만 초보자에게는 (처음하는 것은) 혼란 스럽습니다. 컨트롤러에 상주하는 다른 htaccess 파일이 있지만 기본 프로젝트 폴더에서 htaccess를 편집하거나 추가해야합니다.

    이것은 응용 프로그램, 시스템, 자산, 업로드 등과 같은 파일이있는 codeigniter 폴더입니다.

    Your_project_folder/
    application/
    assets/
    cgi-bin/
    system/
    .htaccess---->(Edit this file if not exist than create it)
    index.php
    

    이 파일을 다음과 같이 변경하십시오.

    <IfModule mod_rewrite.c>
      RewriteEngine On
      # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
      #  slashes.
      # If your page resides at http://www.example.com/mypage/test1
      # then use RewriteBase /mypage/test1/
      # Otherwise /
      RewriteBase /
      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: Anand Pandey
      ErrorDocument 404 /index.php
    </IfModule>
    

    그리고 물론 application / config / config.php에서 두 줄의 코드를 변경해야합니다.

    //find the below code   
    $config['index_page'] = "index.php";
    $config['uri_protocol'] ="AUTO" 
    //replace with the below code
    $config['index_page'] = "";
    $config['uri_protocol'] = "REQUEST_URI";
    
  18. ==============================

    18.Codeigniter의 url에서 index.php를 제거하는 데 필요한 3 단계 만 있습니다.

    Codeigniter의 url에서 index.php를 제거하는 데 필요한 3 단계 만 있습니다.

    1) 응용 프로그램 폴더와 병렬로 .htaccess 파일을 만들고 다음 코드를 복사하십시오.

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

    2) config.php의 $ config [ 'index_page']를 아래와 같이 변경합니다.

    $config['index_page'] = '';
    

    3) 아파치의 "rewrite_module"을 활성화한다.

    아파치와 아파치를 다시 시작하십시오.

    세부 정보 : http://sforsuresh.in/removing-index-php-from-url-of-codeigniter-in-wamp/

  19. ==============================

    19.이 단계를 따르면 문제가 해결됩니다.

    이 단계를 따르면 문제가 해결됩니다.

    1- .htaccess 파일을 https://www.dropbox.com/s/tupcu1ctkb8pmmd/.htaccess?dl=0에서 다운로드하십시오.

    2 번 라인에서 CodeIgniter 디렉토리 이름을 변경하십시오. 내 디렉토리 이름처럼 abc (이름 추가)

    3 - codeignitor 폴더의 주 디렉토리 (abc)에 .htaccess 파일을 저장하십시오.

    4- Config.php 파일에서 uri_protocol을 AUTO에서 PATH_INFO로 변경하십시오.

    참고 : 먼저 apache의 httpd.conf에서 mod_rewrite를 사용하여 주석을 제거해야합니다.

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

    20.이 코드를 사용하십시오. 폴더 이름을 그대로 두 번째 줄을 변경하십시오. 어디 index.php 파일 및 폴더 응용 프로그램, 시스템 폴더가 거짓말. 대부분 문제는 두 번째 줄로 인해 발생합니다. 우리는 프로젝트가있는 폴더 이름을 구성하지 않습니다. 중요한 것은 두 번째 줄입니다. 이것은 index.php를 제거하는 것이 간단합니다.     다시 쓰기 엔진 켜기     RewriteBase / project_folder_name     RewriteCond % {REQUEST_FILENAME}! -f     RewriteCond % {REQUEST_FILENAME}! -d     RewriteRule. * index.php / $ 0 [PT, L]

    이 코드를 사용하십시오. 폴더 이름을 그대로 두 번째 줄을 변경하십시오. 어디 index.php 파일 및 폴더 응용 프로그램, 시스템 폴더가 거짓말. 대부분 문제는 두 번째 줄로 인해 발생합니다. 우리는 프로젝트가있는 폴더 이름을 구성하지 않습니다. 중요한 것은 두 번째 줄입니다. 이것은 index.php를 제거하는 것이 간단합니다.     다시 쓰기 엔진 켜기     RewriteBase / project_folder_name     RewriteCond % {REQUEST_FILENAME}! -f     RewriteCond % {REQUEST_FILENAME}! -d     RewriteRule. * index.php / $ 0 [PT, L]

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

    controller / config.php 파일로 이동하십시오.

    config [ 'index_url'] = '';

    더 많은 연구를위한 참고 자료.

    https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html

    https://ellislab.com/blog/entry/fully-removing-index.php-from-urls

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

    21.이 답변 외에도 index.php를 추가하거나 편집 할 수 있습니다 (이미있는 경우). - 보안을 위해 index.php를 비활성화하고 웹 사이트 디렉토리의 파일을 나열한 다음 내용을 다음과 같이 변경하십시오.

    이 답변 외에도 index.php를 추가하거나 편집 할 수 있습니다 (이미있는 경우). - 보안을 위해 index.php를 비활성화하고 웹 사이트 디렉토리의 파일을 나열한 다음 내용을 다음과 같이 변경하십시오.

    <?php
       header('location:your_required_starting.php'); 
    ?>
    
  22. ==============================

    22.application \ config \ config.php 파일로 이동하여 index.php를 제거 할 수 있습니다.

    application \ config \ config.php 파일로 이동하여 index.php를 제거 할 수 있습니다.

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

    로 변경

    
     $config['index_page'] = '';
    
    
  23. ==============================

    23..htaccess 파일에 다음 코드 행을 추가하십시오.

    .htaccess 파일에 다음 코드 행을 추가하십시오.

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

    어디에서 '내 프로젝트는 프로젝트 폴더 이름입니다.

    CodeIgniter에 대한 자세한 내용을 보거나 .htaccess 파일을 여기에서 다운로드 할 수 있습니다.

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

    24.사소한 일 : (선택 사항)

    사소한 일 : (선택 사항)

    주의해야 할 중요한 사항은 다음과 같습니다.

    내 vhosts 파일 스크립트 : (이전)

    <VirtualHost *:80>
        DocumentRoot "/path/to/workspace"
        ServerName ciproject
        ErrorLog "/path/to/workspace/error.log"
        CustomLog "/path/to/workspace/access.log" common
        Directory   "/path/to/workspace">
            Options Indexes FollowSymLinks
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory> 
    </VirtualHost>
    

    내 vhosts 파일 스크립트 : (이후)

    <VirtualHost *:80>
        DocumentRoot "/path/to/workspace"
        ServerName ciproject
        ErrorLog "/path/to/workspace/error.log"
        CustomLog "/path/to/workspace/access.log" common
        Directory   "/path/to/workspace">
            Options Indexes FollowSymLinks
            #AllowOverride None
            Order allow,deny
            Allow from all
        </Directory> 
    </VirtualHost>
    

    나는 같은 문제에 직면 해 약 1 일 동안 고생했다. 나중에, 시행 착오 방법으로이 것을 발견했습니다. 이것을 제거한 후, 제 일이 성취되었습니다. 이제 URL이 index.php를 조회하지 않습니다. :)

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

    25.위의 모든 해결책이 프로젝트 폴더에서 작동하지 않으면 index.html과 index.php의 두 파일이되며 index.html의 이름을 index_1.html로 변경하고 프로젝트를 탐색합니다.

    위의 모든 해결책이 프로젝트 폴더에서 작동하지 않으면 index.html과 index.php의 두 파일이되며 index.html의 이름을 index_1.html로 변경하고 프로젝트를 탐색합니다.

  26. ==============================

    26.추가 된 "?" 문자 ".php"뒤에, 특히 CodeIgniter를 사용할 때 :

    추가 된 "?" 문자 ".php"뒤에, 특히 CodeIgniter를 사용할 때 :

    그것은 여러 가지 다른 것들에 달려 있습니다 .. 작동하지 않으면 다른 옵션을 시도하십시오!

  27. from https://stackoverflow.com/questions/19183311/codeigniter-removing-index-php-from-url by cc-by-sa and MIT license