抱歉,找不到您要查找的页面。 silex错误

问题描述 投票:5回答:5

我的.htaccess:

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /silex/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>

index.php文件:

<?php
ini_set('display_errors', 1);
require_once __DIR__.'../vendor/autoload.php';

$app = new Silex\Application();

$app->get('/hello/{name}', function ($name) use ($app) {
return 'Hello '.$app->escape($name);
});

$app->run();

访问localhost / silex / hello / world时出现此错误:

“抱歉,找不到您要查找的页面。”

为什么?

php .htaccess silex
5个回答
1
投票

在你的.htaccess尝试这个

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /silex/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?$1 [QSA,L]
</IfModule>

文件的位置应该是:

/silex/.htaccess
/silex/web/index.php

1
投票

这是silex的完整路径

/var/www/html/silex

“.htaccess”文件

/var/www/html/silex/.htaccess

<IfModule mod_rewrite.c>
Options -MultiViews

RewriteEngine On
RewriteBase /silex/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

“index.php”文件

/var/www/html/silex/web/index.php

require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app['debug'] = true;
$app->get('/', function () {
    return 'Index Page';
});
$app->get('/hello', function () {
    return 'Hello Page';
});
$app->run();

1
投票

.htaccess应该是

<IfModule mod_rewrite.c>
Options -MultiViews

RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>

VirtualHost文件必须如下所示

<VirtualHost *:80>
ServerName site.com
ServerAlias www.site.com
DocumentRoot /var/www/html/silex/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

一切都像魅力一样! ;-)

“.htaccess”位于/ var / www / html / silex /

和Silex应用程序包

放在/ var / www / html / silex / web /


0
投票

您可以尝试添加:

RewriteCond %{REQUEST_FILENAME} !-d.

它对我有用。


0
投票

这可能有效:

<IfModule mod_rewrite.c> 
      Options -MultiViews 
      RewriteEngine On 
      RewriteBase /silex/web 
      RewriteCond %{REQUEST_FILENAME} !-f 
      RewriteRule ^ index.php [QSA,L] 
</IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.