Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL without domain Laravel 4

Tags:

laravel-4

Please how can I have URLs like :

 <a href="/auth/register">Signup</a> 

instead of :

 <a href="http://domain.tld/auth/register">Signup</a> 

in Laravel 4? And which is the best for SEO ?

like image 292
Nabil Lemsieh Avatar asked May 22 '14 23:05

Nabil Lemsieh


1 Answers

If you use URL::route() or URL::action() then you can generate relative urls because those functions accept an absolute/Boolean parameter, for example check the route method in URL class:

// route
public function route($name, $parameters = array(), $absolute = true, $route = null)

Or the action method:

// action
public function action($action, $parameters = array(), $absolute = true)

If you use these methods then you may generate relative urls using something like this:

URL::route('routename', array(), false) // requires a named route
URL::action('HomeController@getIndex', array(), false);

Here the third parameter false is being used to generate a relative url, by default it's true. For the second question check this answer and this article as well.

I prefer the default (absolute url) and named route always, so generating urls become easy by referencing the route name and it's easy to change any url without touching the code because named routes allow us to use the route name instead of the url to generate it.

like image 188
The Alpha Avatar answered Dec 11 '22 06:12

The Alpha