2014-01-07 25 views
1

我是新的CodeIgniter和index.php是一個痛苦的屁股。如何重定向index.php與CodeIgniter是一個子頁面

我想要一些友好的網址,但我的網站位於子文件夾中。

我安裝了乾淨的CodeIgniter安裝,爲測試目的添加了另一個視圖,這就是我所得到的。

Page 1 
http://www.example.com/webadmintest/ 
http://www.example.com/webadmintest/index.php/welcome/index 

Page 2 
http://www.example.com/webadmintest/index.php/welcome/byebye 

這是完美的。

現在,在配置文件中我改變了這個:

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

,並在應用程序文件夾中添加.htacces這(我不知道這是地方或根笨文件夾)

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{REQUEST_URI} ^application.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

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

我stil可以加載之前的鏈接,但如果我嘗試去這個鏈接,它會將我發送到主www.example.com頁面。

Page 1 
    http://www.example.com/webadmintest/ 
    http://www.example.com/webadmintest/welcome/index 

Page 2 
http://www.example.com/webadmintest/welcome/byebye 

我也嘗試使用:

$config['base_url'] = '/webadmin/'; 

RewriteBase /webadmintest/ 

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

正如你可以看到這是不是典型的問題,我的意思是可能如果這是一個獨立的網站我p robably不會有這個問題,但需求需要網站成爲主要網站的子文件夾。

感謝

+0

可能重複[刪除的index.php從URL - 笨2](http://stackoverflow.com/questions/5155333/remove-index-php-from-url-codeigniter-2) –

+0

你想刪除文件index.php或者你只是想從網址中刪除? –

+0

我希望它從URL中刪除 – bucur89

回答

0

終於找到了答案。

這適用於任何人誰的笨子文件夾

首先在\子文件夾\應用\ CONFIG \ config.php文件

你必須要找到這些行並與這些更改:

$config['base_url'] = 'http://www.example.com/subfolder/'; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

接下來,您必須修改\ subdfolder \ application.htaccess本:

Options -Indexes 
Options +FollowSymLinks 
<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase /subfolder/ 

    #Removes access to the system folder by users. 
    #Additionally this will allow you to create a System.php controller, 

    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ index.php?/$1 [L] 

    #When your application folder isn't in the system folder 

    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> 
    ErrorDocument 404 /index.php 
</IfModule> 

然後在\子文件夾中創建一個新的.htaccess。htaccess以及添加以下代碼:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 

RewriteCond %{REQUEST_FILENAME} !-d 

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

感謝@ saurabh2836 ADN @Robin摩根

1

我猜你有你的mod_rewrite的,如果不是Get mod_rewrite here

在app文件夾> config文件夾>的config.php

$config['index_page'] = 'index.php'; -> $config['index_page'] = ''; 
+0

我做到了,仍然沒有去。 – bucur89

+0

重新安裝codeigniter並使用mod_rewrite重試。 – hubert

+0

我將CI安裝在一個新文件夾中,並且全部從頭開始,沒有任何事情發生。 – bucur89

相關問題