Routes PHP Silex路由基本url

Routes PHP Silex路由基本url,routes,silex,base-url,Routes,Silex,Base Url,我的项目只是子文件夹中本地服务器上的测试API项目。所以我的url应该是http://localhost/test-project-x/api/。其中有一个index.php 根路由可通过上面的URL获得。但我一进入http://localhost/test-project-x/api/test我有一辆404。要使其正常工作,我需要将PHP路径从$app->get('/test'.更改为$app->get('/test-project-x/api/test'. 我想让它与/test一起工作。但在

我的项目只是子文件夹中本地服务器上的测试API项目。所以我的url应该是
http://localhost/test-project-x/api/
。其中有一个index.php

根路由可通过上面的URL获得。但我一进入
http://localhost/test-project-x/api/test
我有一辆404。要使其正常工作,我需要将PHP路径从
$app->get('/test'.
更改为
$app->get('/test-project-x/api/test'.

我想让它与
/test
一起工作。但在我的一生中,我似乎无法理解/记住如何

test-project-x/api/index.php

<?php    
require_once __DIR__.'/../../vendor/autoload.php';

$app = new Silex\Application();
$app['debug'] = true;

$app->get('/test', function() use($app) {
    return 'This would be the test route.';
});

$app->get('/', function() use($app) {
    return "This would be the root.";
});

$app->run();

只需将RewriteBase与正确的文件夹一起使用即可:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /test-project-x/api/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php [QSA,L] 
</IfModule>

重新启动发动机
重写BASE/test-project-x/api/
重写cond%{REQUEST_FILENAME}!-f
重写规则^(.*)$index.php[QSA,L]
现在,您的路由位于/test-project-x/api文件夹中

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /test-project-x/api/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php [QSA,L] 
</IfModule>