2012-01-08 85 views
0

有很多教程討論從url中刪除index.php。但我希望向前邁進一步。CodeIgniter - 重寫url

鏈接是:www.example.com/index.php/controller/function/single-variable 我希望它像:www.example.com/some-name-that-i-put/single-variable

我找不到教程來做這樣的事情。怎麼做?

回答

3

我不是肯定你是否想這樣做的直接URL重寫CI是如何做的開箱與否的...但是這是你怎麼做網址重複寫:

類/功能/ ID example.com/news/article/13調換到:下的application/config /編輯這些您的config.php文件 :example.com/class/function/ID

http://codeigniter.com/user_guide/general/urls.html

你可以做兩件事情設置此

approx line 80: $config['uri_protocol'] = 'REQUEST_URI'; // i set this to request_URI as it always works for me.. 
approx line 93: $config['url_suffix'] = '.html'; // this is optional, if you want /13.html 
approx line 62: $config['index_page'] = ''; //set this to blank 

創建HTTP根目錄的.htaccess:

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

這是你怎麼做URI路由變化

,如果你想改變URI的機構中,你可以使用URI路線在routes.php中定義,如下所述:http://codeigniter.com/user_guide/general/routing.html

+0

URI路由變化是我正在尋找的。 – gzg 2012-01-08 18:03:49

+1

在這種情況下,您可以簡單地使用正則表達式來定義重新映射。用戶指南將其用純英文表示。 – gorelative 2012-01-08 18:05:06

0

嘗試在你的配置文件的地方,這些

 $config['uri_protocol'] = 'AUTO'; 
    $config['url_suffix'] = ''; 
    $config['index_page'] = ''; 
    $config['allow_get_array'] = TRUE; 
    $config['enable_query_strings'] = FALSE; 

在此之後做出.htaccess文件在你的根目錄下,並把這個

RewriteEngine On

的RewriteCond%{REQUEST_FILENAME}!-f

的RewriteCond%{REQUEST_FILENAME}!-d

重寫規則^(。*)$的index.php/$ 1 [L]

這將絕對幫助你