Codeigniter url routing query string - codeigniter

i need to routing my website url to seo friendly url, get out this issue?
please check the screen shot.
http://prntscr.com/ke8uf0

Try this. In routes.php:
$route['products/(:any)'] = 'products/index/$1';
In your controller:
public function index($product_name) { ... }

In folder applicaion -> config-> routes.php
$route['badrumsutrustning/(:any)'] = 'products/index/$1';

Related

Laravel route url and vuejs axious not working with unicode utf-8 issue

I use my project in slug . when i use English that work fine.But when i use unicode/bangla its show in this picture .
axious not working
IT solved
Axious sent request: axios.get(en/blog/${encodeURI(this.$route.params.id)}).then(response => {
this.blogpostdetails = response.data.blogpostdetails;
});
And Controller: $blogpost = Blog::with('blogcategorylist','admin','blogcomment')->whereSlug(urldecode($id))->get()->first();
Change your request like this, it'll help
let url = http://127.0.0.1:8000/en/blog/${this.$route.params.id};
axios.get(encodeURI(url))
And in your controller just take it as usual

CodeIgniter Routing urls for Search term SEO friendly

I have a problem to make my search urls more SEO Friendly and none of the solutions in stackoverflow worked for me, I tried everything.
Currently my search urls are like this :
https://www.example.com/search?s=Cars&location=London,UK&lat=0.0000&lng=0.0000
I want the url to look like this
https://www.example.com/find/Cars-London,UK/0.0000/0.0000
My Search class looks like this
class Search extends CI_Controller {
public function __construct() {
parent::__construct();
check_installer();
$this->load->helper('url','form');
$this->load->model('Home_Model');
$this->load->model('Cars_Model');
$this->load->model('Search_Model');
$this->load->dbforge();
}
public function index(){
$this->load->view('config');
if($this->input->post() )
{
echo $this->load->view('search/tmpl/search_ajax','',true);
die();
}
$data['meta_setup'] = "search";
$this->load->view('search/search',$data);
}
In routes whatever I tried it didn't work. I'm open to any suggestion to make this url SEO friendly.
You need to go to your routing controller abd manually change your route to specific uri you want
here is a link to how to create a user friendly uri
link : https://www.codeigniter.com/user_guide/general/routing.html

Laravel routing hide path

I have a route like this
http://localhost:8000/produk/slug-product
I want to my url like this, remove produk in url
http://localhost:8000/slug-product
What should I do ?
Do not use .htaccess to handle this. Define route for slugs without any segment at the end of the routes list in your app:
Route::get('{slug}', 'FrontController#getBySlug');
So, all requests which are not related to any of the routes, will go to the getBySlug method:
public function getBySlug($slug)
{
$data = Model::findBySlug($slug);
....
}

Codeigniter Changing routes makes $this->uri->segment() not working

I've altered routes.php
$route['category']='Home/category';
for making url look like www.website.com/category insteead of www.website.com/Home/category. Since Home is my default controller.
but if i am using $this->uri->segment(); inside category function, its not working. this is my controller
class Home extends CI_Controller {
public function category()
{
$value=$this->uri->segmet(3);
}
}
And my url is www.website.com/category/books
I am getting result if I dont alter routes. But by altering routes, I need this to work. Please help me. Thanks
You can debug what you have there by:
var_dump($this->uri->segment_array());
this will give you array of all segments in URI.
Also you can try to debug with this method:
var_dump($this->uri->rsegment_array());
this will give you array of all routed segments in URI
Respectivelly, you can use $this->uri->segment() or $this->uri->rsegment() what ever you find more appropriate for your application.
hello please check segment spelling in your code
class Home extends CI_Controller {
public function category()
{
$value=$this->uri->segmet(3); //wrong
$value=$this->uri->segment(3);
}
}
First of all you need to load URL library and than if your URL is:
www.website.com/category/books
And you want to get books from URL than segment should be:
$value=$this->uri->segment(2); //books
My URL libraries are in autoload. Anyway I solved it. I just configured my routes like this
$route['category/(:any)']='Home/category/$1'

how to remove controller name in url in codeigniter

My Current URL Is
http://myaliveidea.com/news/detail/hello/71/In-Ireland-hiking-for-ancient-relics-hidden-by-fog
Then i want to remove controller name
In this URL the controller name is == detail
and function name id = hello
So i want my URL Like this
http://myaliveidea.com/news/hello/71/In-Ireland-hiking-for-ancient-relics-hidden-by-fog
Try this code in routes.php :
$route['hello/(:any)'] = "detail/hello/$1/$2";
or
$route['hello/(:num)/(:any)'] = "detail/hello/$1/$2";
in application/config/routes.php, rewrite the url like this:
$route['news/hello/(:num)/(:any)'] = "news/detail/hello/$1/$2";
I am not sure about the news part, if it is a subfolder in the controller folder than the above line is ok, if CI in installed in news subfolder, then please remove the news part from both side.
Make sure to accept the parameter values from the hello method like this:
public function hello($id = null, $slug = null)
You can change uri path with routes, here there is documentation

Resources