【发布时间】:2015-10-25 18:06:45
【问题描述】:
这是我想要的网址:http://localhost/project/api/,错误是:
抱歉,找不到您要查找的页面。
我的结构,我在 api et api/www 中有 2 个 htaccess:
- project
-- api
--- app
--- src
--- www
项目/api/:
<IfModule mod_rewrite.c>
# project/api/.htaccess
RewriteEngine On
RewriteBase /project/api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ www/$1 [QSA,L]
</IfModule>
项目/api/www htaccess :
<IfModule mod_rewrite.c>
# project/api/www/.htaccess
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ app.php [L]
</IfModule>
对于 RewriteBase,我尝试附加 /project/api/www/ 但它也不起作用。
当 URL 为 http://localhost/justwrite/api/www/ 时,我得到了我的“hello world”
编辑: 这是我的项目/api/www/app.php:
<?php
require_once __DIR__.'/../../vendor/autoload.php';
$app = new Silex\Application();
echo 'test';
$app->get('/', function () {
return 'Hello ';
});
$app->run();
奇怪的是“测试”出现在 URL http://localhost/project/api/。
编辑 2: 如果我输入:
$app->get('project/api/', function () {
return new Response('Welcome');
});
'Welcome' 显示,也许我可以在 Silex 中设置一个参数来使用这种语法:$app->get('/', ...)?
【问题讨论】:
-
你是否从 apache 启用 mod_rewrite 模块。
-
是的,在 httpd.conf 中我取消了 LoadModule rewrite_module (OSX) 的注释,并且我还有 AllowOverride All。
-
你可以检查是否添加此规则选项+FollowSymLinks -MultiViews
-
它没有改变任何东西。如果有帮助,我在帖子中添加了我的 app.php。 ^^
标签: php apache .htaccess mod-rewrite silex