Automatically switch Symfony front web controllers using .htaccess

Posted by ryan on 2008-07-21 in 1-0, routing, symfony
Ok here's a quick tutorial on how to enable application switching in Symfony with minimal fuss ... yes we love the sound of that!

Modify your .htaccess file

Edit your web/.htacces file and locate the lines that look like this:


  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ index.php [QSA,L]
 

Duplicate the above and modify to your linking:


  # no, so we redirect to our back web controller
  RewriteRule ^myadmin(.*)$ admin.php [QSA,L]
 
  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ index.php [QSA,L]
 

The ^myadmin(.*)$ is the URL so you should have no pages on your public application that start with this.

Update your routing.yml

Edit your backend/config/routing.yml file like so:


homepage:
  url:   /myadmin
  param: { module: default, action: list }

default_symfony:
  url:   /symfony/:action/*
  param: { module: default }

default_index:
  url:   /myadmin/:module
  param: { action: index }

default:
  url:   /myadmin/:module/:action/*
 

Launchpad - Our Latest Projects

move to previous design move to next next design