I have exactly the same configuration and it works! The only difference is that I map api.domain.com to www.domain.com/api instead of your site www.domain.com, so my api link points to www / api, not www.
.htaccess solution
You can use a modification of one of the scenarios described below so that you do not need a symbolic link :
/htdocs/public/.htaccess:
First enable the code to keep the HTTP / HTTPS protocol redirected (I will read this code for all my examples):
RewriteEngine on RewriteCond %{HTTPS} =on RewriteRule ^(.*)$ - [env=proto:https] RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ - [env=proto:http]
Redirect Code:
RewriteCond %{HTTP_HOST} ^api\.domain\.com$ [NC] RewriteRule ^(.*)$ %{ENV:proto}://domain.com/api/$1 [L]
This will redirect all api.domain.com/$1 requests to domain.com/api/$1 . Or you can just use http://domain.com/$1 if you want.
EDIT: if you do not want to hardcode the domain, you can use % N backlinks :
Symlink Solution
I) Regarding the symbolic link, it is strange that you do not see the symbolic link via FTP. I see this in FileZilla as a directory (as if it were a hard link). Try installing FileZilla (and use explicit FTP over TLS for secure authentication).
II) Options +FollowSymLinks should be enabled, but in most hosting environments you cannot install it yourself . Depends on whether the hosting company allowed you this option on AllowOverride Options . You can easily find out:
- type
Options +FollowSymLinks in /htdocs/public/.htaccess - create a symbolic link www / foo.php pointing to www / app.php
- try to access foo.php
- alternatively, if the hosting provider gives you access to the serverβs log, you can see if there was an error in the log.
If this fails, you should ask your hosting provider to either install Options +FollowSymLinks globally or allow AllowOverride Options globally.
Scenarios
I actually have 4 scenarios (you can check them online in my domain) using different methods (suppose the main directory is named / public, as in your case):
1) avif.birds.cz redirects to birds.cz/avif/(canonical) - a solution with a symbolic link
/ public / avif - a symbolic link to / public / www / avif
/public/www/avif/.htaccess:
RewriteCond %{HTTP_HOST} ^avif\.birds\.cz$ [NC] RewriteRule ^(.*)$ %{ENV:proto}://birds.cz/avif/$1 [L]
2) cap.birds.cz redirects to birds.cz/avif/some_url (no symbolic link required)
/public/.htaccess:
RewriteCond %{HTTP_HOST} ^(www\.)?cap\.birds\.cz$ [NC] RewriteRule ^(.*)$ %{ENV:proto}://birds.cz/avif/cap_intro.php [L]
3) (www.) Birds.cz/jpsp redirects to jpsp.birds.cz (canonical)
/ public / jpsp - symbolic link to / public / www / jpsp
/public/www/jpsp/.htaccess:
RewriteCond %{HTTP_HOST} !^jpsp\.birds\.cz$ [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^(.*)$ %{ENV:proto}://jpsp.birds.cz/$1 [L]
4) www.rorysi.cz - an alias domain served by the same tree (rorysi.cz should remain as a canonical domain)
The PHP source for this domain is different, placed under / public / www / rorysi.
/public/www/.htaccess:
RewriteCond %{HTTP_HOST} ^(www\.)?rorysi\.cz$ [NC] RewriteCond %{REQUEST_URI} !^/rorysi/ [NC] RewriteCond %{REQUEST_URI} !=/rorysi [NC] RewriteCond %{REQUEST_URI} !^/lib/ [NC] RewriteRule ^(.*)$ %{ENV:proto}://www.rorysi.cz/rorysi/$1 [L]
Note: the lib directory contains PHP libraries and embedded materials, so I do not want this to be redirected.
Perhaps some of these scenarios may be helpful or inspiring to you.