Oleksandr Savchenko
Oleksandr Savchenko

Reputation: 692

How I can move Symfony2 SonataAdminBundle from "/admin" route to "admin" subdomain

I need to move admin to separate subdomain on Symfony2. How I should configure my routes and security?

Upvotes: 0

Views: 396

Answers (1)

lordrhodos
lordrhodos

Reputation: 2745

For the security part you can easily restrict the security firewall to a specific host (since Symfony 2.4) as described in this official announcement and the documentation.

Here you can see an example of a admin firewall configuration for the domain admin.your-domain.com

security:
    firewalls:
        admin:
            pattern:    ^/
            host:       admin\.your-domain\.com
            http_basic: true

For the routing part you could either refactor your admin-routes to point to / and use the host matching in the routes as described in the official documentation of the routing component.

Here is an example of a route configuration with the host matching option:

admin_dashboard:
    path: /
    host: "admin.your-domain.com"
    defaults: { _controller: AdminBundle:Dashboard:homepage }

Or your could rewrite the urls www.your-domain.com/admin to admin.your-domain.com using the web server configuration. This is an example for apache:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?your-domain\.com$
RewriteRule ^admin/(.*) http://admin.your-domain.com/$1 [R=301,L]

Upvotes: 2

Related Questions