Check if URL in correct format

0

I need to check if the url is in the right format, and if it is not, redirect to the right url.

In other Controller already has a code that does what I need, I just need to adapt it to another Controller , because the format of the url is different.

The code is this:

// redirect to real list_route
if($this->uri->uri_string != $this->blog->url_format($post)) {
  redirect(base_url().$this->blog->url_format($post),'location','301');
  exit;

The function with which it compares in the Model is as follows:

public function url_format($post,$extra=FALSE) {
    $title = isset($post->post_title) ? $post->post_title : $post->title;
    $title = isset($post->url) ? $post->url : $title;
    return $lang_domin.strtolower(url_title($title)).'-postid-'.$post->id.$extra;
}

This code is working perfectly. But the thing is that I need to make the comparison with this function:

public function url_format_category($category,$extra=FALSE) {
    $title = json_decode($category->metadata)->{lang('blog_language')} != '' ? json_decode($category->metadata)->{lang('blog_language')} : $category->title;

    $preffix = trim($title) != '' ? '/'.strtolower(url_title($title)) : '';
    $preffix = trim($category->url) != '' ? '/'.strtolower(url_title($category->url)) : $preffix;
    return site_url(lang('list_route').'/'.$category->id.$preffix);
}

I tried to do this:

public function post_list($category=FALSE,$category_name=FALSE) {
    if($category != FALSE) {
        $data['category_session'] = $this->blog->get_categories($category);
        $this->seo_tags->meta_title = (json_decode($data['category_session'][0]->metadata)->{lang('blog_language')} != '' ? json_decode($data['category_session'][0]->metadata)->{lang('blog_language')} : $data['category_session'][0]->title).' - '.$this->seo_tags->meta_title;

        if($this->uri_string != $this->blog->url_format_category($data['category_session'][0])) {
            redirect(base_url().$this->blog->url_format_category($data['category_session'][0]));
            exit;
        }
    }

But the url returns this way:

  

link

And with this error:

  

Forbidden
  You do not have permission to access / blog / trunk / http: // localhost / blog / trunk / news-and-marketing-strategies-digital-in-our-blog / 1 / seo " > link on this server.

    
asked by anonymous 30.03.2015 / 22:14

1 answer

2

It seems like $this->blog->url_format_category($data['category_session'][0])); is already returning you the entire URL.

Try changing:

  

redirect (base_url (). $ this-> url_format_category ($ data ['category_session'] [0]));

by

  

redirect ($ this-> url_format_category ($ data ['category_session'] [0]));

That is, only removing base_url()

    
02.04.2015 / 16:09