[英]CodeIgniter URL rewriting not work
I'm locked with my system... I changed the settings in my config.php file to have URLs with parameters. 我已经锁定了我的系统...我更改了config.php文件中的设置以获得带参数的URL。 Suddenly I have a product controller that displays the id that I pass URL parameter. 突然,我有一个产品控制器,显示我传递URL参数的ID。
http://localhost:8888/mywebsite/index.php?c=product&m=index&id_product=12 HTTP://本地主机:8888 / mywebsite / index.php的C =产物&M =指数&id_product = 12
This URL works now I want to get a url of the type: 此URL现在可以使用我想获得的类型的URL:
http://localhost:8888/mywebsite/product/my-product-12 HTTP://本地主机:8888 / mywebsite /产品/我的产品-12
So I put this in the .htaccess file: 所以我把它放在.htaccess文件中:
RewriteRule ^product/([a-zA-Z0-9\-]+)-([0-9]+).html$ index.php?c=product&m=index&id_product=$2 [L]
But the page displays : The requested URL /index.php/product/my-product-12.html
was not found on this server. 但页面显示:在此服务器上找不到请求的URL /index.php/product/my-product-12.html
。
My htaccess file : 我的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]
My config.php file : 我的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;
?>
Put your new RewriteRule after RewriteBase: 在RewriteBase之后放置新的RewriteRule:
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]
Because you have to rewrite first to index.php?c=product
因为你必须先重写index.php?c=product
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.