165

現在の URL は次のようになります[mysite]index.php/[rest of the slug]。これらの URL
から削除したい。index.php

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

私のコードイグニタールート.htaccessファイルには、

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

しかし、まだ機能していません。どこが間違っていますか?

4

34 に答える 34

143

ステップ:-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

Step:-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」ファイルを開いて、以下のコードを見つけて置き換えます

//Not needed for CodeIgniter 3 its already there.
//find the below code
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI" 

それだけですが、wamp サーバーでは rewrite_module がデフォルトで無効になっているため機能しません。有効にする必要があります。このために、次のことを行います

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

元のドキュメント

例のリンク

于 2015-03-03T10:03:40.067 に答える
49

ステップ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
于 2014-05-05T07:35:20.530 に答える
16
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 を使用してください

于 2014-03-26T15:10:08.660 に答える
16

ステップ 1 => アプリケーション フォルダーとシステム フォルダーが存在するルート フォルダーに .htaccess ファイルを配置します。

ステップ 2 => yourdomain.com/project/ のようなサブフォルダーを使用する Web パスの場合、htaccess ファイルで次のコードを使用します。

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

yourdomain.com のようなルート フォルダーを使用する Web パスの場合、htaccess ファイルで次のコードを使用します。

RewriteEngine on
RewriteBase    /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
于 2014-09-04T09:27:46.847 に答える
5

これを試してみてください.それは私のために働いているのであなたを助けるかもしれません.

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

コードをルート htaccess ファイルに入れます。

$config['index_page'] = '';

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

問題が発生した場合はお知らせください。

于 2013-10-05T07:47:55.460 に答える
4
+ 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

于 2015-07-23T02:09:10.673 に答える
3

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>

十分な可能性

于 2014-04-11T21:16:09.160 に答える
3

まず、Apache サーバーの書き換えエンジンをオンにする必要があります。このリンクはそのために役立ちます。

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 ファイルになります。今試してみてください。この設定は私にとってはうまくいきます。

于 2015-01-15T05:56:26.080 に答える
1

ルート フォルダーに .htaccess を追加し、次のコードを貼り付けます。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
于 2021-07-28T08:39:15.913 に答える
1

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/

于 2014-05-16T14:05:03.413 に答える
0

これらの回答に加えて、index.php を追加するか、編集することができます (既に存在する場合)。セキュリティのために、とにかく index.php を無効にして、Web サイトのディレクトリにファイルを一覧表示しないようにしてから、コンテンツを次のように変更します。

<?php
   header('location:your_required_starting.php'); 
?>
于 2016-11-24T07:21:54.100 に答える
0

このコードを使用します。フォルダー名があるので、2 行目を変更します。index.php ファイルとフォルダ アプリケーション、システム フォルダが存在する場所。ほとんどの問題は、2 番目の行が原因で発生します。プロジェクトが置かれているフォルダー名は設定しません。重要なのは2行目です。index.php を削除するのは簡単です。RewriteBase /project_folder_name RewriteCond %{REQUEST_FILENAME} の RewriteEngine !-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

于 2014-12-18T04:49:08.360 に答える