I want to remove controller as well as function name from url - php

I need help to rewrite url and remove controller as well as function name from url given url is my current uel.
URL :http://localhost/example/Loadercontrol/detail/200
I want this type of url
URL : http://localhost/example/name (replace id with name).
I already try rewrite url as well as
$route['example'] = 'localhost/example/Loadercontrol/detail';
but it's not working. I've really tried to fix the issue. Please help me.

Try like this..
$route['example/(:num)'] = 'example/Loadercontrol/detail/$1';
For details see more here...https://www.codeigniter.com/userguide3/general/routing.html#wildcards
Wildcards are actually aliases for regular expressions, with :any being translated to [^/]+ and :num to [0-9]+, respectively.

Related

PHP URL Routing; Variables to 'directory'

Is it possible to change
host/index.php?variable=3
to
host/index.php/3
In my instance I'm using
host/bot?id=3
But I'd like it to be
host/bot/3 <-- This will be the only variable EVER used
How can I accomplish this, any links or code you can provide?
Thanks in advance!
GET /hotels/:id Hotels.Show
Segments of the path may be matched and extracted with a : prefix.
The :id variable above will match anything except a slash. For example, /hotels/123 and /hotels/abc would both be matched by the route above.
Extracted parameters are available in both the
Controller.Params map
and via Action method parameters.
https://revel.github.io/manual/routing.html

seo friendly url for codeigniter

We have a social networking web site for students. Our url looks like this domain.com/student/145236 where 145236 is the roll number. We now have an option of doing something like this domain.com/student/145236/student-name but since google / search engines would prefer domain.com/student-name/student/145236 we would like to do like this, but we are unable to do it, we tried doing this using routes $route['(:any)/student/(:num)'] = 'student/$1'; but it shows 404 page, any help would be grateful :)
This should be work for you:
$route['(:any)/student/(:num)'] = 'student/yourfunction/$1/$2'; 
Here $1 is for ist param (:any) and
$2 is for second param (:num) .
For getting values from the URL inside the student controller you can use CI Segments.

How to remove the keyword from the url using htaccess( Mod_rewrite)

mywebsite url looks like below, in that I would like to remove the some of the keyword
http://mywebsite.comn/proto-type/awards/media-center/downloads
Need to be changed to
http://mywebsite.comn/proto-type/media-center/downloads
Please let me know how we can achieve this.
I tried with some of the Rewrite url which is not working.

Prepending the url path in codeigniter?

Generally in CodeIgniter we get this structure of URL :
domain/controller/function
So suppose I went to some user's profile then URL would be :
domain/user/profile/username
How can I change that to
domain/username
OR even more better if
domain/u/username
where the middle part is what i decide.
Any Suggestions?
You can user routes.php for this purpose
Suppose you want a url like
domain/u/username
Then in routes.php you can specify the routing rule like below:
$route['u/(:any)'] = "user/profile/$1";
This specifies that if a url comes like '/u/anyvalue' then execute user/profile/$1
where $1 will be the anyvalue

Quick help - CodeIgniter routing

Need a quick hand on setting custom route for my project.
the code works without any reoute definition as
http://myblog.local/posts/categories/show/1
but I want to access it as following;
http://myblog.local/posts/1
and I've changed my route as following;
$route['posts/(:any)'] = 'posts/categories/show/$3';
But my route declaration seems not working, please help me where i am doing the mistake
$route['posts/(:num)'] = 'posts/categories/show/$1';
Because you have only 1 segment (the first) to match: $1
And the segment must be a number: (:num)
(:any) will work too.
$route['posts/(:num)'] = 'posts/categories/show/$1';
also in config file
make it blank
$config['index_page']='';
hope this might work.

Categories