I have the following structure
/var/www/mysite/public/
/var/www/mysite/api/
In both directories, .htaccess is set up for rewriting url as follow :
dev.domain.com/example/ => dev.domain.com/index.php?token=example
dev.domain.com/api/example => dev.domain.com/index.php?token=example
My apache conf looks like this
...
<VirtualHost *:80>
Servername dev.domain.com
DocumentRoot /var/www/mysite/public/
Alias /api/ "/var/www/mysite/api/"
<Directory "/var/www/mysite/api/">
Options Indexes FollowSymLinks
</Directory>
</VirtualHost>
...
dev.domain.com/api/ works fine (it calls www/api/index.php) but dev.domain.com/api/example/ calls the public site (www/public/index.php with the query string token=example).
I thought that the apache directive Alias was redirecting also the subdirectories, which apparently is not the case. Could someone tell me where I am wrong?
So this was a problem of rewriting : the aliased directory should not be in the pattern to match.
Here is the final config : apache config file
...
<VirtualHost *:80>
ServerName dev.domain.com
DocumentRoot /var/www/mysite/public/
Alias /api/ /var/www/mysite/api/
<Directory /var/www/mysite/api/>
Options FollowSymLinks -Indexes
AllowOverride all
</Directory>
</VirtualHost>
...
and .htacess file the /api/ directory
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301]
RewriteRule ^(.*)/(.*)/$ /api/index.php?object=$1&collection=$2 [QSA,L]
RewriteRule ^(.*)/$ /api/index.php?object=$1 [QSA,L]
Thanks @freedev for your time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With