繁体   English   中英

Code Igniter SEO友好的URL重写

[英]Code Igniter SEO friendly URL rewriting

在codeigniter框架中重写URL时遇到问题。

这是我的网址

http://localhost/article/lg-watch-urbane-vs-moto-360-a-detailed-real-world-comparison/19

我有一个像这样的控制器:

class Article extends CI_Controller {

function __construct()
{
    $this->set_page_name( "View Article" );
}

function index($perma_link="",$id="")
{
    $this->response['article'] = $this->restutil->get("portal/articles/get/".$id,array('id'=>$id))->article;

    $this->render_view('articles/view');
}
}

我的.htaccess是这样的:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

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

    RewriteRule ^article/([\w-]+)$ /index.php/article/index/$1 [L]

</IfModule>

我想将所有来自“文章”的请求重定向到“文章/索引”功能。 但是目前还没有发生。 仅当我在网址中给出“索引”即; HTTP://本地主机/条/指数/ LG-手表彬彬有礼-VS-MOTO-360-A-详细,真实世界的对比/ 19

然后,只有页面正在加载。 否则不是。 有人可以帮我解决这个问题吗?

您将可以使用CI路由执行此操作。

$route['article/(:any)/(:num)'] = 'article/index/$1/$2;

这应该工作。 将文章中包含的所有内容重新路由到index方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM