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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With