Apache 在子域的文件夹中运行Slim Framework

Apache 在子域的文件夹中运行Slim Framework,apache,mod-rewrite,slim,Apache,Mod Rewrite,Slim,我已经为我的APIAPI.server.com设置了一个子域。我可以在这里运行我的应用程序,但我想在该子域的文件夹中运行它。当我尝试这一点时,我得到了404 我修改了我的.htaccess,使用了多条路径,一路返回到root,毫无乐趣 RewriteEngine On # Some hosts may require you to use the `RewriteBase` directive. # If you need to use the `RewriteBase` d

我已经为我的API
API.server.com
设置了一个子域。我可以在这里运行我的应用程序,但我想在该子域的文件夹中运行它。当我尝试这一点时,我得到了
404

我修改了我的
.htaccess
,使用了多条路径,一路返回到root,毫无乐趣

   RewriteEngine On

   # Some hosts may require you to use the `RewriteBase` directive.
   # If you need to use the `RewriteBase` directive, it should be the
   # absolute physical path to the directory that contains this htaccess file.
   #
   # RewriteBase /
   RewriteBase /all/the/way/back/to/root/www/api/v1/
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php [QSA,L]
   RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
我已经试过这里的每一种方法了

  /all/the/way/back/to/root/www/api/v1/
  /the/way/back/to/root/www/api/v1/
  /way/back/to/root/www/api/v1/
  /back/to/root/www/api/v1/
  /to/root/www/api/v1/
  /root/www/api/v1/
  /www/api/v1/
  /api/v1/
  /v1/
但仍然得到404。有什么建议可以解决这个问题吗

这是www/api/v1的实际.htaccess

  RewriteEngine On

  # Some hosts may require you to use the `RewriteBase` directive.
  # If you need to use the `RewriteBase` directive, it should be the
  # absolute physical path to the directory that contains this htaccess file.
  #
  # RewriteBase /
  RewriteBase /api/v1/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule ^(.*)$ index.php [QSA,L]
  RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
我想使用主域作为api网站

运行下面的脚本

  <?php 
  //Gets the document root 
  $root = getenv("DOCUMENT_ROOT") ; 
  Echo $root; 
  ?> 


给我
/var/www/domainname.com/web
将以下
.htaccess
代码放入
www/api
中。卸下
v1
内的
.htaccess

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/v1 [NC]
RewriteRule ^ v1/index.php [L]

RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
我假设
/www
是您网站的
%{DOCUMENT\u ROOT}
目录。
既然您正在以
api.server.com/v1
的身份访问您的站点,请尝试以下
web/api/v1/.htaccess

RewriteBase /v1/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]

与其说是一个解决方案,不如说是一个变通办法。在每个路线前面加上v1,所以原来是
/items/
的路线改为
/v1/items/

请参阅问题以获取答复。您说您的应用程序在api.server.com上运行良好。您的意思是从/api dir提供文件吗?那你的htaccess在哪里?在/www或/www/api?文件将从/api/v1/提供,api中有一个.htacces,v1/api/中的.htaccess有一个RewriteBase/如果这个帮助我假设您的目录结构是
/var/www/domainname.com/web/api/v1
。对吗?