2011-08-14 3 views
-2

私はCodeIgniterを使用しています.htaccessでURLを設定したいと思います。私は多くの方法を試しましたが、まだ成功していません。CodeIgniterで.htaccessを使ってURLを設定するのを助けてください。

マイフォルダ構造:

--application 
----corntrollers 
-------public 
----------home.php 
----------log 
-------------- login.php 
-------admin 
----views 
-------public 
----------home.tpl 
----------log 
-------------- login.tpl 
--system 
--mysite 

私はリライトするURLを設定したい:

http://localhost/mysite/index.php/log/login 
=> 
http://localhost/mysite/log-in 

はどのように私はそれを行うことができますか?

答えて

0

まず、URLの書き換えが有効になっていることを確認し、下のコードで.htaccessファイルを作成してください。

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

そして/config/config.php

/* 
    |-------------------------------------------------------------------------- 
    | Index File 
    |-------------------------------------------------------------------------- 
    | 
    | Typically this will be your index.php file, unless you've renamed it to 
    | something else. If you are using mod_rewrite to remove the page set this 
    | variable so that it is blank. 
    | 
    */ 
    $config['index_page'] = 'index.php'; 

変化

$config['index_page'] 

$config['index_page'] = ''; 

次のページへ

/config/routes.php

$route['log-in'] = "log/log-in"; 
+0

非常にありがとう!それは終わった。 – misakitran

2

のApache2のモジュールをURL書き換えを有効にする:

a2enmod rewrite 

変更/config/config.php

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

$config['index_page'] = ""; 

同様

$config['uri_protocol'] = 'AUTO'; 

$config['uri_protocol'] = 'REQUEST_URI'; 

への.htaccessの正しい方法は次のとおりです。

#AddHandler application/x-httpd-php5 .php 
<IfModule mod_rewrite.c> 
    RewriteEngine On 
    #RewriteBase/

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

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

php_flag short_open_tag on 

<FilesMatch "\.(php)$"> 
FileETag None 

<IfModule mod_headers.c> 
    Header unset ETag 
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" 
    Header set Pragma "no-cache" 
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT" 
</IfModule> 
</FilesMatch> 

Restar Apache2のサービス:

sudo systemctl restart apache2.service 

希望に役立ちます。

関連する問題