CodeIgniter Forums

Full Version: yet another seo url question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]StefanAlexandru[/eluser]
Ok I will show you my whole configuration, but I've tested this and because of reading entries from db by id CI will not care about the next segment of the URI.

Controller (This is the controller which is called when viewing an ad) :

Code:
public function display(){


                 $this->load->model('General');
                 $id=$this->uri->segment(2);
                 $data['anunt']=$this->General->adbyID($id);

                 $this->load->view('ad', $data);
        }

Model :

Code:
public function adbyID($id) {
                $this->db->where('postID', $id);
                $query=$this->db->get('v_ads');

                return $query->result();

View(this is the view from which I am calling the controller/method) :

Code:
<?php  foreach($lastads->result() as $l) : ?>
<?php $url_title = url_title($l->title);?>
<h2>&lt;?php echo anchor("ad/$l->postID/$url_title", "$l->title");  ?&gt;</h2>
&lt;?php echo substr($l->content,0,25);?&gt;
<hr>
&lt;?php endforeach; ?&gt;
&lt;?php echo $links; ?&gt;


and here is my route configuration :
Code:
$route['ad/:num/:any']= '/ad/display';

Because in my controller I am reading only the id, this is what CI cares about, so changing that uri segment the user can play around. Smile

El Forum

[eluser]boltsabre[/eluser]
Hmm, fair enough, I really thought by changing the id in the URL that this causes the whole controller to run again, I mean... if you change the URL, it's a page reload, it should run again. Then again, I'm not real familiar with routes (don't use them very much personally.)

I'll check back here in 6 hours once I'm home and see if you've found a solution, if not I'll check my code and get back to you. Good luck

El Forum

[eluser]StefanAlexandru[/eluser]
Thanks a lot boltsabre for your help. I am waiting for your answer, and I hope that others who had this situation can help us. Smile

El Forum

[eluser]John_Betong_002[/eluser]
[quote author="StefanAlexandru" date="1311794147"]Thanks a lot boltsabre for your help. I am waiting for your answer, and I hope that others who had this situation can help us. Smile[/quote]

Maybe try this in your routes.php
Code:
$route["default_controller"] = "welcome";

// specific URLs  
$x=array("(:any)",'about','contact','terms','blog','subscribe','advertise');
foreach($x as $xx):
    $route[$xx] = "contoller_menu_items";                     // test $this->uri->segment(1)
endforeach;

// numeric items
$route["(:num)"] = "controller_items_numb/$1"; // test $this->uri->segment(1)

// not listed above but still try to find a match
$route["(:any)"] = "controller_item_alpha/$1"; // test $this->uri->segment(1)
&nbsp;
&nbsp;

El Forum

[eluser]StefanAlexandru[/eluser]
Thanks John_Betong_002, I will try this as soon as I get home.

But first can you please explain how $route["(:num)"] will act like ?

I mean www.mydomain.com/10 wil be routed via this rule ?

El Forum

[eluser]John_Betong_002[/eluser]
[quote author="StefanAlexandru" date="1311794713"]Thanks John_Betong_002, I will try this as soon as I get home.

But first can you please explain how $route["(:num)"] will act like ?

I mean www.mydomain.com/10 wil be routed via this rule ?[/quote]

Try this example:


http://johns-jokes.com/1755

http://johns-jokes.com/Browser-comparison-modes/

http://johns-jokes.com/Browser-compariso...sport.html
&nbsp;
&nbsp;

El Forum

[eluser]boltsabre[/eluser]
Okay, so we had some issues at work, had to work back wayyyy late, so sorry in advance about the late reply.

Just had a look at my forum, and indeed you are correct, I can change my id uri, the page reloads with the correct post as represented by the new id, but the seo-title uri does not change! Well I'll be damned. My structure is:

mydomain.com/controller/method/id/seo-title

Personally, I'm made a note of this issue, but it's way down my list of things to look at (as far as I'm concerned it's not a major issue for my website, yours could be different though, my seo uri is only there for ranking purposes, even with this 'bug' of being able to change the id it will not have any impact what so ever as this uri segment is not used for anything at all.) As far as crawling and ranking by SE spiders, this is not going to have any impact in the slightest, they will only follow links that they can get to, so the site will still get crawled correctly.

On quick thought would be to set a session var with the id in it. Each time your controller is called (ie, a user changes the id manually should cause this to happen) just check the id uri segment against the session var, and if it's different force your controller to call the model again to get the correct seo-title. Should work. Not perfect as people can turn sessions off, but it should serve your purpose for 99% of users. Anyway, I'm going to bed. Good luck with it! If you do find a solution please post it on here, I'd be interested to know what you do!
Pages: 1 2