如何使用破折号替换codeigniter url中的下划线? [英] How to replace underscores in codeigniter url with dashes?

查看:133
本文介绍了如何使用破折号替换codeigniter url中的下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的控制器看起来像:

我想知道最简单的解决方案,将我的代码符号的下划线改为破折号,

  public function request_guide(){
...加载视图等...
}

因此,为了浏览此页面,我必须去:

  www.domain.com/request_guide 

但我想更友好,使用破折号而不是下划线,例如:

  www.domain.com/request-guide 

我的印象是codeigniter函数需要下划线(可能是错误的)。



在以前的项目中,我只是使用mod_rewrite,但我相信这些操作可以使用路由。



重写用虚线替换下划线的网址

解决方案

中找到路由配置

  config / routes.php 

您的朋友。



一个简单

  $ route ['request -guide'] =request_guide; 

会为您执行此操作。


I would like to know the simplest solution to changing the underscores of my codeigniter urls to dashes, for seo reasons.

My controllers look like:

public function request_guide() {
...Load view etc...
}

So to browse to this page I would have to go to:

www.domain.com/request_guide

But I want to be more seo friendly and use dashes instead of underscores, like so:

www.domain.com/request-guide

I am under the impression that codeigniter functions require underscores (might be wrong).

In previous projects I have simply used mod_rewrite but I believe that these actions can be performed using routes.

What is the easiest way for me to rewrite the urls replacing the underscores with dashes???

解决方案

The routes config found in

config/routes.php

is your friend here.

A simple

$route['request-guide'] = "request_guide" ;

will do this for you.

这篇关于如何使用破折号替换codeigniter url中的下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆