tags:

views:

563

answers:

6

In development mode my symfony admin/backend app can be accessed at http://localhost/backend_dev.php. For production mode, I created a controller php file, admin.php, so now in production the admin application can be accessed at http://www.domain.com/admin.php.

What do I have to do to allow the admin app to be accessed at domain.com/admin or admin.domain.com?

Thanks!

A: 

Here are some basic ways you could do it:

Either dump admin.php into a folder called 'admin' in the root of www.domain.com, and rename admin.php to index.php. (Easiest solution)

Of course, this way you have to adjust all relative links in admin.php to one level up (appending '../' to the start of all relative urls should work), as well as all absolute links to reflect the changes.

Regarding your admin.domain.com, you should contact your webhost/domain name provider to setup a subdomain for you.


Or if your webhost allows .htaccess files, you could write a mod_rewrite rule.

Sherman
In a big app, this approach is doomed to failure (says he, looking at his scars). Too much maintenance to ensure that relative and absolute URLs go where they should.
dland
A: 

i would create a module called admin...then in presumably the index action I would put whatever you had in your admin.php file.

then in your routing.yml file just point yourdomain.com/admin to the admin/index....that way you keep everything within the symfony front controller

Andrew

Andrew
+1  A: 

You probably are better off putting everything admin like in the admin directory, but you can cheat by using mod_rewrite

RewriteRule ^admin/?$ admin.php [L]
Chris Bartow
A: 

you can open new subdomain an on that subdomain (admin.domain.com) setup virtual host that points to server with your symfony app.

you can look at the full tutorial [here][1].

[1]: http://blog.mirthlab.com/2008/03/04/dynamically-loading-symfony-applications-via-subdomains/ here

deresh
A: 

One of the possible solutions is listed here: http://forum.symfony-project.org/index.php/m/44261/?srch=admin+mod%5Frewrite#msg%5F44261

FractalizeR
A: 

Make sure your DNS resolves the admin.domain.com correctly, then edit .htaccess in the /web to have mod_rewrite pick up on your subdomain and rewrite requests to admin.php. Optionally rename your admin.php to something less obvious or perhaps do a quick subdomain check inside it as well, or extend the rewrite with a 301 redirect if anyone hits domain.com/admin.php.

The following simple .htaccess works for me:

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>
  RewriteEngine On

  # The admin subdomain returns the backend
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{HTTP_HOST} ^admin\.domain\..*
  RewriteRule ^(.*)$ admin.php [QSA,L]

  # Check if the .html version is here (caching)
  RewriteRule ^$ index.html [QSA]
  RewriteRule ^([^.]+)$ $1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f

  # No?, so we redirect to our front web controller
  RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

Change domain to your own domain.

cvaldemar