Codeigniter-지정된 입력 파일 없음


86

저는 Codeigniter의 초보자이고 CI 튜토리얼을보고 간단한 작업을하려고했습니다. CI를 다운로드하고이 파일을 컨트롤러 디렉터리에 추가했지만 작동하지 않습니다.

<?php

class site extends CI_Controller
{
    public function index()
    {
        echo "Hello World";
    }

    function dosomething()
    {
        echo "Do Something";
    }   
}    
?>

http : //..../index.php/site를 사용하여 액세스하려고 하면 출력이 표시됩니다 ... "지정된 입력 파일 없음".... 그런데 파일 이름을 site.php로 지정했습니다.


체크 아웃 시도 이 링크를 하고 문제가 해결되는지 확인합니다.
— Vap0r

노력에 대한 나던 도움 덕분 없습니다
— koool

답변:


291

그냥 ? .htaccess 파일에서 index.php 뒤에 서명하십시오.

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

그리고 그것은 작동 할 것입니다!


나를 위해 이것은 301 리디렉션을 제공하고 URL에서 /? /로 끝납니다.
— Ade

@Ali Mohamed, htaccess 파일 중이 줄을 추가합니까? 시도했지만 효과가 없습니다
— Bahdeng 2014-01-04

1
@Bahdeng 프로젝트 디렉토리의 .htaccess 파일에이 스 니펫을 배치해야합니다.
— Ali Mohamed

응용 프로그램이 루트 디렉터리에없는 경우와 같이 응용 프로그램 디렉터리에 따라 위 줄을 변경합니다. 위 줄 대신 다음 코드를 작성합니다.RewriteRule ^(.*)$ /sub-directory/index.php?/$1 [L,QSA]
— skovy

1
index.php를 외에 CodeIgniter의 루트 디렉토리에있을 것입니다 @NSGodMode
— 알리 모하메드

58

GoDaddy이은에 고정 된 것 같다 호스팅 .htaccess자신이 노력하고,

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

...에

RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

응용 프로그램이 루트 디렉터리에없는 경우와 같이 응용 프로그램 디렉터리에 따라 위 줄을 변경하고 위 줄 대신 다음 코드를 작성합니다.RewriteRule ^(.*)$ /sub-directory/index.php?/$1 [L,QSA]
— skovy

CI 3에서 찾을 수없는 404 페이지
— Nipun Tyagi

38

여기에서이 질문에 대한 답을 찾았습니다 ..... 문제는 호스팅 서버였습니다 ... 시도해 주신 모든 분들께 감사드립니다. .... 이것이 다른 사람들에게 도움이되기를 바랍니다.

Godaddy 설치 팁


응용 프로그램이 루트 디렉터리에없는 경우와 같이 응용 프로그램 디렉터리에 따라 위 줄을 변경합니다. 위 줄 대신 다음 코드를 작성합니다.RewriteRule ^(.*)$ /sub-directory/index.php?/$1 [L,QSA]
— skovy

17

CodeIgniter 앱의 .htaccess 파일에있는 RewriteEngine, DirectoryIndex

방금 .htaccess 파일 내용을 변경했으며 다음 링크에 표시된대로 대답했습니다. 그리고 페이지를 새로 고치려고 시도했습니다 (작동하지 않았고 컨트롤러에 대한 요청을 찾을 수 없음).

그런 다음 의심 때문에 public_html 폴더 내의 .htaccess에 대한 변경 사항 을 원래 .htaccess 콘텐츠로 되돌 렸습니다 . 이제 다음과 같습니다 (원래 그대로입니다).

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

그리고 지금도 작동합니다.

힌트 : 재 작성 규칙이 서버 컨텍스트 내에서 명확하게 설정되지 않은 이전과 같습니다.

내 파일 구조는 다음과 같습니다.

/
|- gheapp
|    |- application
|    L- system
|
|- public_html
|    |- .htaccess
|    L- index.php

그리고 index.php시스템과 응용 프로그램에 대한 다음 경로를 설정했습니다.

$system_path = '../gheapp/system';
$application_folder = '../gheapp/application';

참고 : 이렇게하면 처음에는 애플리케이션 소스 코드가 공개되지 않습니다.

제 대답에 잘못된 점이 있으면 댓글을 달고 다시 수정하십시오!
초보자가이 답변이 도움이되기를 바랍니다.

감사!


1

내 사이트는 MochaHost에 호스팅되어 있습니다. .htaccess 파일을 설정하여 내 URL에서 index.php를 제거 할 수 있습니다. 그러나 인터넷 검색 후이 스레드에 대한 답변과 다른 답변을 결합했습니다. 내 최종 작업 .htaccess 파일에는 다음 내용이 있습니다.

<IfModule mod_rewrite.c>
    # Turn on URL rewriting
    RewriteEngine On

    # If your website begins from a folder e.g localhost/my_project then 
    # you have to change it to: RewriteBase /my_project/
    # If your site begins from the root e.g. example.local/ then
    # let it as it is
    RewriteBase /

    # Protect application and system files from being viewed when the index.php is missing
    RewriteCond $1 ^(application|system|private|logs)

    # Rewrite to index.php/access_denied/URL
    RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]

    # Allow these directories and files to be displayed directly:
    RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|app_upload|assets|css|js|images)

    # No rewriting
    RewriteRule ^(.*)$ - [PT,L]

    # Rewrite to index.php/URL
    RewriteRule ^(.*)$ index.php?/$1 [PT,L]
</IfModule>
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.