I am trying to get pretty URLs on Codeigniter. Basically, here’s what I want.
//http://website.com/State/City/Neighborhood/Zip => http://website.com/search?lotsofParams=1234
$route['/State/City/Neighborhood/Zip'] = "search?location=blahblahblah&Submit=Search";
I am willing to write the routes manually, but right now that code isn’t working. Any idea how I can get this working?
no you are using QUERY STRINGS you can't route query string to friendly slashed urls.
You can re-write them with htaccess
Related
I want to implement a link in my application, but instead of it following this format:
/origin/{number}
I want it to look like this:
/origin=number
How do I implement a route successfully which will understand this link format? Surely Laravel is flexible enough to not only be able to parse slash-based URLs?
This should work:
Route::get('/origin={number}', ...);
I have a website that is developed with CodeIgniter. I have added the route for my url as follows:
$route['about_us'] = 'about-us';
Now I have a problem with that. I.e. when I am looking for the url www.mysite.com/about_us it works and at same time www.mysite.com/about-us is also working. I want only one url to work: the one with the underscore.
I have removed this to:
$route['about_us'] = 'about-us';
But the url www.mysite.com/about-us still works. It may cause duplicate content for my website in Google and so more page links also showing. Even I don't have that functions too. Like www.mysite.com/about_us/design. Likewise in about_us controller file index function only there, but design method calling in Google.
How do I resolve this problem?
You actually don't need a route here. The normal purpose of request routing the way you are using it is so that you can use hyphenated URLs when hyphens are not permitted in class and function names. I.E. you want the url to by www.example.com/test-controller, but you can't actually name a controller test-controller because the hyphen is illegal.
If you only want to have the underscored URL such as www.mysite.com/about_us then just remove the route completely and name the controller about_us. With no routing rules the hyphenated url should 404.
Kohana have a smart routing system, I like feature when I can get url by route(Route::get('route_name',params), How implement this feature to codeigniter? Result that I need http://site.com/Sunglasses/Novus/202/ss14.05.html
Thanks
CodeIgniter doesn't support this feature (some would call it "reverse routing").
Maybe I'm not understanding the question properly as I haven't used Kohona, but if you just want to get the uri segment, you would use:
$this->uri->segment(3); //=202 in http://site.com/Sunglasses/Novus/202/ss14.05.html
To route a url with params you would use something like the following:
$route['products/(:any)/(:num)'] = "products/get_product/$1/$2";
so for example with this you could have a url of site.com/products/sunglasses/202 routing to the get_product() method of your products controller and then you would pick up the uri segment as above.
my journey of learning MVC continues and as hard as it is, I'm learning a lot of things I could never learn otherwise. Now I have faced the problem in routing. Currently I'm taking the $_SERVER["REQUEST_URI"] and get the controller and method and any args. When url is in format http://mysite.com/forum/thread/12/1123 there is no problem but I need to catch also requests like http://mysite.com/index.php?forum=12&&thread=1123.
I have read links in threads below but cannot get my head on QSA and I though I would better ask.
Thanks
mod_rewrite: Check for Custom query string in URL?
Rewrite url with query string in htaccess
I ended up writing something like before:
I redirect using htaccess
//No Controller specified in url (The current url is base url like http://example.com/hosanna_framework/)
if(!isset($_GET['base_url'])){
$url = $config["router"]["default_controller"];
}
//Controller is specified in url
else{
$url = $_GET['base_url'];
}
I'm having a little trouble with a CodeIgniter route when there is a query (stuff after the ?) in the URI. I know it is good practice to replace queries with routes in CI, but I'm importing in a premade messageboard that already does everything with queries. This is my route:
$route['messageboard/:any'] = "messageboard/index";
Any in this case refers to a script name. So if it's messageboard/admin.php, I have it load a view that loads my premade messageboard's script "admin.php". It's working just fine if I do messageboard/admin.php. It does fine if I do messageboard/admin.php?. If I put a parameter into the query, however, the route won't correctly send the user to the messageboard controller, and instead sends them to a 404. Does anyone have any ideas on how to make this work? I would be eternally grateful. Thanks!
Okay guys, I solved it. I needed to change three things. The first was mtvee's suggestion, which lets it read query strings. The second one you're going to want to change the $config['permitted_uri_chars'] in the config file to include an equals sign, since it starts off disabled and all query strings will be of the for ?a=34 or something like that. The third is you need to go to $config['uri_protocol'] and change it from AUTO to PATH_INFO. Once I did those, it worked.
I'm sure the syntax is:
$route['messageboard/(:any)'] = "messageboard/index"; //<-- notice brackets
and not
$route['messageboard/:any'] = "messageboard/index";
I believe CI doesn't do GET out of the box. Check out Enabling Query Strings here http://ellislab.com/codeigniter/user-guide/general/urls.html