2016-07-05 134 views
1

我被我的系統鎖定了...... 我改變了我的config.php文件中的設置,使URL帶有參數。 突然我有一個產品控制器,顯示我傳遞URL參數的id。CodeIgniter URL重寫不起作用

http://localhost:8888/mywebsite/index.php?c=product&m=index&id_product=12

該URL的工作,現在我想的那種類型的網址:

http://localhost:8888/mywebsite/product/my-product-12

所以我把這個.htaccess文件中:

RewriteRule ^product/([a-zA-Z0-9\-]+)-([0-9]+).html$ index.php?c=product&m=index&id_product=$2 [L] 

但該頁面顯示:請求的網址/index.php/product/my-product-12.html找不到 on thi s服務器。

我htaccess文件:

#Options +FollowSymLinks 
RewriteEngine on 
RewriteBase/

RewriteCond $1 !^(index\.php|public|\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1   [L,QSA] 

RewriteRule ^product/([a-zA-Z0-9\-]+)-([0-9]+).html$ index.php?c=product&m=index&id_product=$2 [L] 

我的config.php文件:

<?php 

$config['base_url'] = 'http://localhost:8888/mywebsite/'; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'QUERY_STRING'; 
$config['url_suffix'] = ''; 
$config['enable_hooks'] = TRUE; 
$config['allow_get_array']  = TRUE; 
$config['enable_query_strings'] = TRUE; 
$config['controller_trigger'] = 'c'; 
$config['function_trigger']  = 'm'; 
$config['directory_trigger'] = 'd'; 
$config['rewrite_short_tags'] = FALSE; 

?> 

回答

0

把你的新重寫規則RewriteBase後:

RewriteEngine on 
RewriteBase/

RewriteRule ^product/([a-zA-Z0-9\-]+)-([0-9]+)$ index.php?c=product&m=index&id_product=$2 [L] 

RewriteCond $1 !^(index\.php|public|\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1   [L,QSA] 

因爲你必須先改寫到index.php?c=product

+0

感謝您的回答! 我這樣做,我在我的頁面中有這個錯誤信息: 找不到 在此服務器上找不到請求的URL /index.php。 – xenos92

+0

現在嘗試不使用'.html'。這是在你的代碼,但不是在你的例子URL。 – Croises

+0

同樣的結果...我不明白:( – xenos92