2016-07-05 55 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