简体   繁体   English

Code Igniter SEO友好的URL重写

[英]Code Igniter SEO friendly URL rewriting

I'm facing issues while rewriting URLs in codeigniter framework. 在codeigniter框架中重写URL时遇到问题。

Here is my URL 这是我的网址

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

And I've a controller like this : 我有一个像这样的控制器:

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');
}
}

And my .htaccess is like this: 我的.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>

I want redirect, all the request which comes as "article" to "article/index" function. 我想将所有来自“文章”的请求重定向到“文章/索引”功能。 But it is not happening currently. 但是目前还没有发生。 Only if i give "index" in the URL ie; 仅当我在网址中给出“索引”即; http://localhost/article/index/lg-watch-urbane-vs-moto-360-a-detailed-real-world-comparison/19 HTTP://本地主机/条/指数/ LG-手表彬彬有礼-VS-MOTO-360-A-详细,真实世界的对比/ 19

Then only the page is loading. 然后,只有页面正在加载。 Otherwise it is not. 否则不是。 Can anybody help me fix this? 有人可以帮我解决这个问题吗?

You'll be able to do this, with CI routes. 您将可以使用CI路由执行此操作。

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

This should work. 这应该工作。 Re-routes anything that comes into article, to the index method. 将文章中包含的所有内容重新路由到index方法。

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

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