Welcome Guest, Not a member yet? Register   Sign In
How to SEO URL Rewriting
#1

[eluser]newbiewcoder[/eluser]
Hello everybody.
I have an app that have URL like this:
http://localhost/mysite/news/detail/123

news is my controller, detail is my function that will accept argumen (123)

I want to make the URL like this:
http://localhost/mysite/news/detail/this...f-the-news

I want to totally masking/remove the id of the news, and replace it with the real title of the news from the database.

Can I achieve this goal?

Thanks
#2

[eluser]Raphael Passini[/eluser]
Why dont you create a column in the table on the database named 'url_title', then load the news using this field.

Something like that:

Code:
function detail($title) {
   $this->db->get_where('table', array('url_title' => $title));
   ...
}
#3

[eluser]ciGR[/eluser]
Hi and wellcome!
I agree with Raphael and I suggest you to take a look at
Code:
url_title()
function from the url helper, this function will help you to have better urls formats. For more details look at http://ellislab.com/codeigniter/user-gui...elper.html
#4

[eluser]newbiewcoder[/eluser]
Thanks both for you Raphael and ciGR. That't work for me.
And url_title() just fine to, it save the time to make better URL.

And BTW I need one (maybe two or more) open source app based on CI other than bambooinvoice. Learning from the sample give a better result. Don't you?

Thanks alot.
#5

[eluser]Unknown[/eluser]
url_title() works just fine.

However I noticed that it doesn't properly replace dots (.) and separators ($search) into replace ($replace).

If you open url_helper.php and see at url_title() function you will see

Code:
$trans = array(
        '&\#\d+?;'        => '',
        '&\S+?;'          => '',
        '\s+'             => $replace,
        '[^a-z0-9\-\._]'  => '',
        $replace.'+'      => $replace,
        $replace.'$'      => $replace,
        '^'.$replace      => $replace,
        '\.+$'            => ''
    );

adding those 2 lines will make it work:

Code:
$trans = array(
        '&\#\d+?;'        => '',
        '&\S+?;'          => '',
        '\s+'             => $replace,
        '[^a-z0-9\-\._]'  => '',
        '\.'              => $replace, // line 1
        $search           => $replace, // line 2
        $replace.'+'      => $replace,
        $replace.'$'      => $replace,
        '^'.$replace      => $replace,
        '\.+$'            => ''
    );

cheers,




Theme © iAndrew 2016 - Forum software by © MyBB