My Symfony 2 installation is on a shared hosting site. Directory structure:
public
|-- api // subdomain api.mydomain.com
|-- app
|-- bin
|-- m // subdomain m.mydomain.com
|-- src
|-- vendor
|-- www // symfony "web" folder
| |
| +-- app.php // front controller!
Folder www
is the main folder and it's the folder where the front controller resides. It's bounded to mydmain.com
or www.mydomain.com
. Subdmains like m.mydomain.com
or api.mydomain.com
are folders inside the public
one (i.e. m
or api
).
I've no SSH access but only FTP (no SFTP). The problem is not repeating the content of www
inside m
and api
folder. If I copy all the content from www
to api
(say) the front controller is working and I'm able to work with subdomains in Symfony 2.
What I've tried so far:
Symlink solution
Creating a symlink api
poiting to www
folder. I've used the folling script placed inside www
folder:
<?php
var_dump(__DIR__); // /htdocs/public/www where script is executed
$target = '/htdocs/public/www';
$link = '/htdocs/public/api';
if(file_exists($link)) {
if(is_link($link)) {
echo "unlinking $link...";
var_dump(unlink($link));
echo "symlinking $link to $target...";
var_dump(symlink($target, $link));
} else {
exit("$link exists but not symbolic link\n");
}
}
echo readlink($link); // /htdocs/public/www correct!
echo exec('cd .. && ls -l');
Output:
/htdocs/public/www
unlinking /htdocs/public/api... bool(true)
symlinking /htdocs/public/api to /htdocs/public/www... bool(true)
/htdocs/public/www
drwxr-xr-x 7 nobody nobody 4096 Nov 25 18:57 www
Symlink is created but (this is strange) I'm not able to see it connection through FTP or with the file manager interface (web). Front controller doesn't work. Symlink it's there, I'm getting an error if I try to create a folder with the same name as the symlink.
.htaccess solution
How can I route all requests for api
folder to www
folder (or from api subdomain to www subdomain)? This solution seems not quite correct to me (why a 301 redirect for GET /users api.mydomain.com
)?