web-dev-qa-db-ja.com

URLからindex.phpを削除するCodeIgniter

私の現在のURLはこの[mysite]index.php/[rest of the slug]のように見えます。
これらのURLからindex.phpを削除したいです。

私のApache2サーバではmod_rewriteが有効になっています。 configでは、$config['index_page'] = '';

私のcodeignitorルート.htaccessファイルには、

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

それでもまだ機能していません。どこが悪いの?

136
Nihar Sarangi

以下を試してください

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コードはホスティングサーバーによって異なります。いくつかのホスティングサーバー(例:ゴダディ)で余分なものを使用する必要がありますか?上記のコードの最後の行に。該当する場合、次の行が最後の行に置き換えられます。

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

Step:-1「application/config」フォルダを開き、「config.php」ファイルを開きます。 config.phpファイルで以下のコードを見つけて置き換えます。

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

Step:-2CodeIgniterフォルダに移動して.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サーバ以外ではうまくいきません。これのために以下をしなさい

  1. WAMPアイコンを左クリック
  2. アパッチ
  3. Apacheモジュール
  4. Rewrite_moduleを左クリック

元のドキュメント

リンク例

112
Salim

ステップ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 mod rewriteを有効にしました(コマンド)

Sudo a2enmod rewrite

ステップ5:

Apacheを再起動(コマンド)

Sudo /etc/init.d/Apache2 restart
33
Dino
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]

あなたがこの順序でURLを持っているならsite.com/index.php/class/method/id

注意:config.phpのindex.phpを削除するのはconfig [index_page] = ""であるべきです

注意:最後の行の違いに注意してください。$ 0ではなく$ 1を使用してください。

16
user3464848

ステップ1 =>あなたの.htaccessファイルをアプリケーションとシステムフォルダが存在するルートフォルダに置いてください。

ステップ2 =>サブフォルダを使用してあなたのWebパスが - 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]
15
vinod

2つのステップがあります。

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]
11
shafi

あなたの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]

お役に立てれば。

10

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'] = ''に変更

5
Manish Sharma
  1. .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. 変化する

    $config['index_page'] = ''; 
    

index.phpファイルにあるconfig.phpを削除する

  1. サーバーから書き換えます。
5

それを試してみてください。

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

あなたのルートのhtaccessファイルにコードを入れてください。

$config['index_page'] = '';

あなたの設定ファイルで。

あなたが何か問題に直面した場合私に知らせてください。

4
ABorty
+ 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

4
KH SolveCode

まず最初にApacheサーバーの書き換えエンジンをon.thisにしなければなりません。

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ファイルになります。今それを試してみてください。この設定は私のために働く。

3

まあこれらすべての答えは良いですが初心者にとっては(これは初めてです)これらは混乱を招きます。コントローラに常駐する他の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の2行のコードを変更する必要があります。

//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";
3
Anand Pandey
  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.
2

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>

十分な可能性

2
abbas hussen

開発と生産の両方

    # 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]
2
cgwCode

Codeigniterでurlからindex.phpを削除するのに必要な手順は3つだけです。

1)アプリケーションホルダーと並行して.htacessファイルを作成し、次のコードをコピーしてコピーします。

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)Apacheの“ rewrite_module”を有効にしてください。

Apacheを再起動すれば完了です。

詳細: http://sforsuresh.in/removing-index-php-from-url-of-codeigniter-in-wamp/

1
Suresh Kamrushi

2つのステップでそれを解決しました。

  1. 設定ファイルapplication/config/config.phpの2つのパラメータを更新します
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
  1. ルートフォルダのファイルを更新する。htaccess
<IfModule mod_rewrite.c>
    RewriteEngine On
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

私はあなたのすべての設定は良いと思いますがあなたはあなたの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]
1
Yaseen Ahmad

あなたのporjectのベースディレクトリに.htaccessファイルを作成することで、index.phpをURLから削除することができます。

RewriteEngine on
RewriteCond $ 1!^(index.php |資産|画像| js | css |アップロード| favicon.png)
RewriteCond%(REQUEST_FILENAME)!-f
RewriteCond%(REQUEST_FILENAME)!-d
RewriteRule ^(。*)$ ./index.php/$1 [L]

そのファイルを保存し、config.phpファイルでの変更も正しい

$config['index_page'] = '';

うまく走りたい

0
Rabab Sh

これらのコード行を.htaccessファイルに追加してください。

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

私のプロジェクトはあなたのプロジェクトフォルダ名です。

あなたはCodeIgniterについてもっと読むことができるか、あなたはここから.htaccessファイルをダウンロードすることができます

0
Infolet.org

application\config\config.phpファイルに移動してindex.phpを削除することができます。

 
 $ config ['index_page'] = 'index.php'; // index.phpを削除します
 

への変更

 
 $ config ['index_page'] = ''; 
 
0
Rafiqul Islam

.htaccessにコードを追加することで、URLからindex.phpを削除できます。

ファイルパス:root> .htacess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


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

それがうまくいくことを願っています。

0
Rokan Nashp

あなたの問題は解決するでしょうこれらのステップに従ってください

1-ここから.htaccessファイルをダウンロードします https://www.dropbox.com/s/tupcu1ctkb8pmmd/.htaccess?dl=0

2- 5行目のCodeIgnitorディレクトリ名を変更します。私のディレクトリ名がabcのように(あなたの名前を追加してください)

3-あなたのcodeignitorフォルダのメインディレクトリ(abc)に.htaccessファイルを保存します

4- Config.phpファイルでuri_protocolをAUTOからPATH_INFOに変更

注意:まずコメントを削除してapachiのhttpd.confからmod_rewriteを有効にする必要があります。

0
Salman Khan

上記の解決策がすべてうまくいかない場合は、プロジェクトフォルダ内でindex.htmlとindex.phpの2つのファイルになります。index.htmlをindex_1.htmlに変更してプロジェクトを参照してください。

0
Mohsin Shoukat

これらの答えのほかに、index.phpを追加するか編集することができます(既にある場合) - セキュリティのために、あなたのウェブサイトディレクトリのファイルをリストアップすることからとにかくindex.phpを無効にしたい -

<?php
   header('location:your_required_starting.php'); 
?>
0
bennyhardjono

追加された「?」との違いに注意してください。特にCodeIgniterを扱う場合、 "。php"の後の文字:

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

vs.

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

それは他のいくつかのことに依存します..うまくいかない場合は、他のオプションを試してください!

0
eyal_katz

このRewriteEngineを試してみてください

        # Removes index.php from ExpressionEngine URLs
        RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
0
Kashif

このコードを使ってください。 2行目を自分のフォルダ名に合わせて変更します。 index.phpファイルとフォルダのアプリケーションは、システムフォルダにあります。主に問題は2行目が原因で発生します。プロジェクトが置かれているフォルダの名前は設定しません。重要なのは2行目です。これはindex.phpを削除するのは簡単です。 RewriteBase/project_folder_nameのRewriteEngine 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-remove-index.php-from-urls

0

軽微なこと:(オプション)

仮想ホストの書き換えエンジンのステータスをRewrite ONに更新した後で、Apacheを再起動してみてください。

気をつけるべき重要なこと:

Apache vhostsファイルで、このスクリプト行があるかどうかを確認してくださいAllowOverride Noneはいの場合、この行を削除/コメントしてください。

私の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を検索しません:)

0
Lalith Kumar