user2794692
user2794692

Reputation: 391

Symfony2 routing.yml to external url

My question is: How can I generate external url from routing.yml?

I want something similar to:

documentation_product1:
    pattern:  /my/documentation/product1.php
    default:  http://www.myothersite.com/product1

Is it possible or something similar?

Upvotes: 2

Views: 2361

Answers (2)

Nextar
Nextar

Reputation: 1098

It is possible to redirect within a controller to an external site

documentation_product1:
pattern:  /my/documentation/product1.php
defaults:  { _controller: AcmeBundle:Product:show }

// in controller
$this->redirect('http://www.myothersite.com/product1');

But it is not a good practise.

It is better to use the RedirectController from the FrameworkBundle.(mantioned by Paulpro)

Doku:

http://symfony.com/doc/current/cookbook/routing/redirect_in_config.html

https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

Upvotes: 6

colburton
colburton

Reputation: 4715

Symfony routes the requested url to a pair of controller and action to execute. It does only internal redirects.

For a redirect to an external URL you need .htaccess and mod_rewrite (if you use apache).

Upvotes: -1

Related Questions