Laravel Route gives Object not found error - laravel

So i had a route to create a post that was like http://127.0.0.1:8000/posts/create and now I am trying to delete the word create completely and have my route as http://127.0.0.1:8000/posts/ the problem is when i put nothing after the (/) I get Object not found Error, but when i put anything even one letter after the (/) it works.
Is not it allowed for a POST method to be used where its url ends with a slash? I'm confused

Ok, that was silly, the problem was that i'm adding a / at the end of the route while it should be /posts and that is it, no / after posts

Related

How to pass file path with '/' to route laravel?

How can we pass file path to route like this,
<a href={{route('route.name',['path'=>'uploads/xyx/'.$id.'/'.$attachment_name])}}>download</a>
However, I would like this to hit
Route::get('download/{path},'Controller')->name('route.name')
When I hit this route my url got transformed somehow like this -> download/uploads/44/filename which is causing not found exception!
I want to pass the path as a parameter, where slashes should have to be ignored! so that I can get full path in my controller!
As per the documentation you can do this:
"The Laravel routing component allows all characters except /. You must explicitly allow / to be part of your placeholder using a where condition regular expression"
Route::get('download/{path}', ...)->where('path', '.*');
Laravel 7.x Docs - Routing - Parameters - Encoding Forward Slashes
use get parameter remove {path}
Route::get('download,'Controller')->name('route.name')
in blade
<a href={{route('route.name',['path'=>'uploads/xyx/'.$id.'/'.$attachment_name])}}>download</a>
this will generate url like route.name?path=download/uploads/44/filename
still u will get data in controller like $request->path

Codeigniter URL routing solution for my website

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.

Laravel 4 - Duplicate Url

I am having a problem with the confide package for user authentification.
My problem is that when I login, I am redirected to the login page which throws an notFoundHttpException because the url I am redirected to is duplicated... looks like this:
http://www.mypage.dev/http://www.mypage.dev
My virtual host is set up like this here
https://github.com/daylerees/laravel-website-configs/blob/master/apache.conf
What is making this happen?
---EDIT---
Gathering more experience...
It seems that this occurs when the following redirect is used:
return Redirect::action('Controller#action')
If I use:
return Redirect::to('/action')
everything is just fine.
My route look like this:
Route::get('/action', 'Controller#action');
Change your Route to
Route::get('action', 'Controller#action');
Your current route's definition appends /action to the end of the current URL.
Because of the underscore, the url http://newsletters_app.dev is invalid according to filter_var($url, FILTER_VALIDATE_URL). Because of this, HTML::link() is generating a duplicate base. Solution is to simply remove the underscore from the URL.

how to match regex route in Sinatra?

i'm trying to make this code snippet from the sinatra tutorial work so that I can set some routes based on regex matching. it doesn't seem to be working and I'm copy pasting direct from the tutorial, any ideas on what i'm missing. make the assumption that my sinatra app is working and i have other correctly structured GET routes working so I'm unclear why a direct copy past like this doesn't work.
get %r{/hello/([\w]+)} do
"Hello, #{params[:captures].first}!"
end
should correct map a route for http://0.0.0.0:4567/hello but is routing to a 'sinatra doesn't know this ditty' error message.
Thks.
%r{/hello/([\w]+)} doesn't match /hello at all. Your regex requires a slash and another string, but your path doesn't include that.
That route would match /hello/there but not /hello or even /hello/.
And given that you are looking at the captures, you probably don't even want this to work with /hello at all since that capture would be nil and who want to say hello to nil?

Remove controller name from codeigniter 2 url path

I am having trouble removing the controller name from my url path on my localhost.
i have this url - localhost:8888/localhost/site_name/
i have been able to remove index.php from the url using my htaccess similar to http://codeigniter.com/wiki/mod_rewrite so that:
localhost:8888/localhost/site_name/index.php/controller_name
is now:
localhost:8888/localhost/site_name/controller_name/
but i can't remove the controller name from the path so that:
localhost:8888/localhost/site_name/controller_name/function_name/
becomes:
localhost:8888/localhost/site_name/function_name/
I am using only one controller, and i have added:
$route['^(function_name1|function_name2|function_name3)(/:any)?$'] = 'controller_name/$0';
$route['^(?!ezstore|ezsell|login).*'] = "home/$0"; /*similar variation i tried*/
and other variations to my routes file but it does not have any effect. i also tried using the _remap function but that does not help in this case.
Any help will be appreciated! Thanks
You can use a wildcard route,
$route['(:any)'] = "controller_name/$1";
Then when if you go to http://localhost/function_one/param1
it will call the controller controller_name the function function_once and pass param1 as the first parameter.
nb: I must point out, using only one controller for an entire site does raise warning bells for me, you may want to get your code design checked out, but that's just me.

Resources