Drupal website specialists. Call us about your project on (02) 8006 3402

Automatically switch Symfony front web controllers using .htaccess

Posted 21/July/2008 by neubreed

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/*