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


답변:


90

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
링크 +1! 약간 조정해야했지만. 이걸로 얻었습니다-> RewriteCond % {REQUEST_FILENAME}! -f RewriteCond % {REQUEST_FILENAME}! -d RewriteRule ^ (. *) $ index.php / $ 1 [QSA, L]
— OrangeRind

어떤 이유로 RewriteCond 시작 부분에 슬래시를 추가해야했습니다. RewriteCond $1 !^\/(index\.php|assets|robots\.txt)
— 헨리

어떤 이유로 URL에 index.php가 있으면 실제로 제거되지 않고 그대로 유지되고 계속 작동합니다.
— CMCDragonkai 2013

1
나는 가능한 모든 조합을 사용했지만 여전히 나를 위해 작동하지 않습니다 !!!!! 어떻게 작동하게 되었습니까 ??
— Roshdy

.htaccess 파일을 확인하도록 Apache 설치를 구성해야합니다.이 경우인지 확인하십시오.
— Sean Vieira

60

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';

여전히 운이 없으면 하위 폴더를 포함하도록 다시 쓰기 규칙을 변경하십시오. 개발 서버 등에서 임시 URL을 사용하는 경우 종종 문제가됩니다.

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

이 옵션을 가지고 놀기만하면됩니다. 또한 색인 파일이 다음으로 설정되어 있는지 확인하십시오.

$config['index_page'] = '';

행운을 빕니다!


나는 여기에 당신의 첫 번째 코드가 나를위한 해결책이라고 생각했지만 실제로 domain / *과 같은 URL을 domain / index.php에 보내는 것은 도메인 / 환영을 환영 컨트롤러에 보내는 것이 아닙니다. 그때 잠시 흥분했습니다. 지금 다른 제안을 시도하십시오.
— jsky

31

index.php 파일과 함께 응용 프로그램 루트 디렉터리에 .htaccess 파일이 있습니다. (htaccess 확장자가 올바른지 확인하십시오. Bz 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';

3
D : UR 방법은 버터처럼 일 이유하지만 난 오랜 시간 몰라이에 실패되었습니다 감사합니다
— 아메드 새미

1
감사합니다 MDeSilva. 이 게시물은 내 시간을 절약합니다.
— 상디

1
감사. 작동합니다. BTW, config.php를 변경할 필요가 없습니다.
— Stony

1
고마워요, 이것은 저를 도왔습니다. WAMP
— T.Coutlakis

21

system\application\config\config.php파일을 살펴보면 다음과 같은 변수가 있습니다.index_page

다음과 같이 보일 것입니다.

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

그것을 변경

$config['index_page'] = "";

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

참고 : CodeIgniter v2에서이 파일은 시스템 폴더에서 application\config\config.php


9

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

<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>

     ...


정말 감사합니다. AllowOverride None도 얻었습니다. 이제 작동합니다!
— Willy

블로그는 이제 사라졌고 나는 그것을 읽고 싶었습니다. 이 솔루션 중 어느 것도 저에게 효과가 없습니다 ...
— Kevin Beal

대단해, 내 하루를 구했다.
— JChow 2014-06-14

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

RewriteRule. * index.php / $ 0 [PT, L]을 프로젝트 폴더 이름 "codeigniter"로 변경 한 후 작동합니다. 귀하의 지원에 감사드립니다.


6

1 단계 => 응용 프로그램 및 시스템 폴더가있는 루트 폴더에 .htaccess 파일을 저장합니다.

2 단계 => yourdomain.com/project/와 같은 하위 폴더를 사용하는 웹 경로 인 경우 htaccess 파일에서 다음 코드를 사용합니다.

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

루트 폴더를 사용하는 웹 경로-yourdomain.com-다음 코드를 htaccess 파일에 사용하십시오.

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

위의 예제 중 첫 번째를 사용하여 시도한 것은 내 루트에서만 작동하지만 폼로드에서는 작동하지 않습니다. url에서 index.php를 사용하려고 시도 할 것입니다. 내가 그것을 실행할 수 있다면 이것으로 돌아올 것입니다
— Sam

감사합니다 @Vinod. 나는이 문제로 미쳐 가고있었습니다. 나는 오랫동안 인터넷에서 검색하고 다양한 솔루션을 시도했지만 솔루션을 발견하기 전까지는 작동하지 않았습니다. 이제 CI 프로젝트가 작동 중이며 새로운 희망을 얻었습니다. CI로 이동합니다. 고마워요 :)
— gomesh munda

5

내가 추가 할 거라고 생각 했어

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”

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

이건 확실히 효과가있을거야 .. 시도 해봐


4

활성화했는지 확인하십시오 mod_rewrite(하지 않았습니다).
사용하려면:

sudo a2enmod rewrite  

또한 다음으로 교체하십시오 AllowOverride None.AllowOverride All

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]  

나는 가능하게하기 위해 필요한 다른 모듈을했다 actions: stackoverflow.com/questions/14419757/...
— Jasdeep Khalsa

4

완벽한 솔루션 [로컬 호스트 및 실제 도메인에서 테스트 됨]

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

3

이것은 내 CI 프로젝트 중 하나에 대한 .htaccess입니다.

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

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



3

.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입니다.


3

codeigniter의 URL 경로에서 index.php를 해결하는 두 가지 방법이 있습니다.

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

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

에

$config['index_page'] = '';

2 : 생성되지 않은 경우 루트 경로에 .htacess를 생성하고, 다음 코드를 복사합니다.

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

저장 한 다음 Apache 구성 rewrite_module 또는 mod_rewrite가 활성화되어 있는지 확인합니다. 그렇지 않으면 활성화하십시오. (최상의 접근)!


이것은 정확하고 CodeIgniter 문서에서 바로 나온 것입니다. 이 방법도 사용합니다.
— Dewald Els

2

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

이 htaccess 사용

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

확실히 당신은 할 수 enabled mod_rewirte로모그래퍼phpinfo();

그런 다음 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';

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

가끔 사용 : REQUEST_URI대신 AUTO또는 "QUERY_STRING"goDaddy 호스팅


2

찾는 위치 \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]

그것은 나를 위해 작동합니다, 당신도 희망합니다.


2

리눅스에서 apache2 서버를 사용하는 경우 .htaccess 파일의 변경 사항과 함께 apache2.conf 파일을 재정의해야 할 수도 있습니다. /etc/apache2/apache2.conf 에서 apache2 구성 파일을 찾으십시오 .

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

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

1

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

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


2
몇 시간을 보낸 후이 글을 읽고 실수를 발견했습니다.
— mohsin.mr 2013

나는 또한이 "작은"속임수 때문에 적어도 한 시간을 보냈다. 기본적으로 .htaccess 파일은 application루트가 아닌 디렉토리에 있습니다.
— vadim

1

나는 많은 해결책을 시도했지만 내가 생각 해낸 것은 다음과 같습니다.

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]

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



0

이 코드를 .htacess 파일의 응용 프로그램 폴더에 붙여 넣는 데 도움이됩니다.

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>

0

이것은 나에게 완전한 마법을 주었다.

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]

도움이 되었기를 바랍니다.


0

안녕하세요

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 응용 프로그램이 도메인 이름 / 폴더 /index.php와 같은 하위 도메인으로 호스팅되는 경우 폴더는 하위 폴더의 이름입니다.

그것이 당신을 위해 일하기를 바랍니다. 감사.


0

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

이 코드가 질문에 답할 수 있지만이 코드가 질문에 대한 이유 및 / 또는 답변 방법 에 대한 추가 컨텍스트를 제공 하면 장기적인 가치가 향상됩니다.
— Benjamin W.

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

0

1 단계 :

htaccess 파일에 추가

<IfModule mod_rewrite.c> 
RewriteEngine On 
#RewriteBase / 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [QSA,L] 
</IfModule>

2 단계 :

codeigniter 구성에서 index.php 제거

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

3 단계 :

Apache 구성에서 htaccess 재정의 허용 (명령)

sudo nano /etc/apache2/apache2.conf 파일을 편집하고 다음으로 변경하십시오.

AllowOverride All

www 폴더 용

4 단계 :

Apache 모드 재 작성 활성화 (명령)

sudo a2enmod 재 작성

5 단계 :

Apache 다시 시작 (명령)

sudo /etc/init.d/apache2 restart
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.