【问题标题】:Code Igniter SEO friendly URL rewritingCodeigniter SEO 友好的 URL 重写
【发布时间】:2015-07-30 01:25:05
【问题描述】:

我在 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>

我想要重定向,所有以“文章”形式出现的请求到“文章/索引”功能。但目前还没有发生。仅当我在 URL 中给出“索引”时,即; http://localhost/article/index/lg-watch-urbane-vs-moto-360-a-detailed-real-world-comparison/19

然后只有页面正在加载。否则不是。谁能帮我解决这个问题?

【问题讨论】:

标签: php .htaccess codeigniter url-rewriting seo


【解决方案1】:

使用 CI 路由,您将能够做到这一点。

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

这应该可以。将文章中的任何内容重新路由到 index 方法。

【讨论】:

    猜你喜欢
    • 2016-05-28
    • 2021-07-06
    • 2015-01-04
    • 2011-12-24
    • 2013-07-30
    • 1970-01-01
    • 2011-03-02
    • 2014-10-06
    • 2017-04-01
    相关资源
    最近更新 更多