Laravel 4 - Duplicate Url - laravel

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.

Related

Laravel 5.7 Passing a value to a route in a controller

My controller posts a form to create a new page. After posting the form I need to redirect the user to the new page that will have the contents for that page that were entered in the previous form. If I simply do return view('mynewpageview', compact('mycontent')); where my mycontent is the object used to execute the $mycontent->save(); command, I carry the risk for someone refreshing the url thus posting the same content twice by creating a new page.
Instead I would like to redirect the user to the actual page url.
My route is
Route::get('/newpage/{id}', 'PageController#pagebyid'); and if I use return redirect()->route('/newpage/$pageid'); where $pageid = $mycontent->id; I get Route not defined error.
What would be the solution either to stop someone from resubmitting the content or a correct syntax for passing the parameter?
The correct answer that works for me is -
Give your route a name in the routes file
Then pass the parameters with an array as shown below in the controller.
return redirect()->route('newpageid', ['id' => $pageid]);
With basic (unnamed) routes, the correct syntax was return redirect('/newpage/'.$pageid);
You have already found out you can alternatively use named routes.
Last but not least, thanks for having considered the "double submit" issue! You have actually implemented the PRG pattern :)

CodeIgniter routes are not working

I've defined following route in config file as follows.
$route['apartments/(:any)'] = 'apartments/view/$1';
If I give http://localhost/apartment_advertisement/apartments/shobha_complex like this in url it works perfectly fine.
If I give http://localhost/apartment_advertisement/apartments/shobha_complex/abcd/abcd like this in url it goes to the same page as above. So I needed error page for this url. Please help me how to control these urls?. The work would be more appreciated.
Do you mean display an 404-not-found error when request URL has an unwanted "tail"? You can modify (:any) to restrict accepted string. It's simple:
$route['apartments/(\w+)'] = 'apartments/view/$1';

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.

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.

How do I change the login URL using Tank auth?

I have been looking around the Tank auth code to see how things are done, but it seems a little confusing to find out how to change the path of the default login.
I wanted to change it to groups/login or users/sign_in, but that wasn't an easy task. I'm wondering whether I should change that from the routing file or any other file.
Any idea how to get around with this little issue?
I'm wondering whether I should change that from the routing file
Yes, that's exactly what URI Routing is for:
$route['your/desired/url'] = 'auth/login';
If you need to kill the old URL for some reason, you can set it to something empty:
$route['auth/login'] = FALSE;
Unfortunately, the Tank Auth login url is assumed to be auth/login, and there are several redirects that must be edited. I recommend adding a custom config setting to config/tank_auth.php:
$config['login_url'] = 'your/desired/url';
Then replace all occurrences of redirect('/auth/login') with:
redirect($this->config->item('login_url', 'tank_auth'));
in the Auth controller and anywhere else it appears.
Why not just change the name of the controller from 'Auth' to whatever you want? Seems the shortest route to me.

Resources