0
I need to check if the url is in the right format, and if it is not, redirect to the right url.
In another Controller
already has a code that does what I need, I just need to adapt it to another Controller
, because the url format 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 he makes the comparison 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 point is that I need to compare to 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 it this way:
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:
And with this mistake:
Forbidden
You don’t have permission to access /blog/trunk/http://localhost/blog/trunk/novidades-e-estrategias-de-marketing-digital-in-our-blog/1/seo on this server.
A thousand options. Web server configuration files (Nginx, Apache etc.), Framework route configuration, specific route configuration to access the online-system... If you put the codes you have access to and are creating, we can make suggestions. I normally use the route and controller settings in the Framework.
– Fernando Cordeiro
@Fernandocordeiro I use Codeigniter. I have the routes specified in the Routes file. And that’s exactly what I need to do, from the route and controller settings.
– GWER
I believe the most coherent is: if the url has some wrong data or even the parameter, which is directed to the 404 page in the function
show_404();
Or redirect to a default route if you do not find your page (Slug, register) in the database if you have:$routes['novidades/(:any)'] = 'blog/padrao';
– user21846
What your model in
$this->blog->url_format($post)
takes as parameter and which format of the returned string?– user21846
@GWER Please edit the question and add all this information instead of leaving it as comments... then delete the comments. This information is part of the issue.
– Miguel Angelo
I edited my question and entered more information. @Miguelangelo
– GWER