Url rewriting 在Silex PHP框架中重写url

Url rewriting 在Silex PHP框架中重写url,url-rewriting,silex,Url Rewriting,Silex,我是Silex框架的新手,我对url重写有问题 问题: 当我在浏览器中键入此内容时->http://localhost/mysite/它正在工作并加载索引视图 $app->get('/', function() use($app) { return $app['twig']->render('index.twig.html'); }); 但是当我输入http://localhost/mysite/about $app->get('/about', function

我是Silex框架的新手,我对url重写有问题

问题:

当我在浏览器中键入此内容时->
http://localhost/mysite/
它正在工作并加载索引视图

$app->get('/', function() use($app) {

    return $app['twig']->render('index.twig.html');

});
但是当我输入
http://localhost/mysite/about

$app->get('/about', function() use($app) 
{ 
    return $app['twig']->render('about.twig.html');
});
它给我以下错误:
请求的URLhttp://localhost/mysite/about 在此服务器上找不到。

如果我键入此url
http://localhost/mysite/index.php/about

$app->get('/about', function() use($app) 
{ 
    return $app['twig']->render('about.twig.html');
});

这个url正在运行,我不明白为什么?我需要加载此视图,但url中不包含index.php。我怎么做?提前感谢。

将此用作
.htaccess
文件的内容(基于Symfony标准版提供的内容)


重新启动发动机
RewriteCond%{REQUEST_URI}:$1^(/.+)/(.*):\2$
重写规则^(.*)-[E=基:%1]
RewriteCond%{ENV:REDIRECT_STATUS}^$
重写规则^index\.php(/(.*)|$)%{ENV:BASE}/$2[R=301,L]
RewriteCond%{REQUEST_FILENAME}-f
重写规则[L]
重写规则.?%{ENV:BASE}/index.php[L]

将其用作
.htaccess
文件的内容(基于Symfony标准版提供的内容)


重新启动发动机
RewriteCond%{REQUEST_URI}:$1^(/.+)/(.*):\2$
重写规则^(.*)-[E=基:%1]
RewriteCond%{ENV:REDIRECT_STATUS}^$
重写规则^index\.php(/(.*)|$)%{ENV:BASE}/$2[R=301,L]
RewriteCond%{REQUEST_FILENAME}-f
重写规则[L]
重写规则.?%{ENV:BASE}/index.php[L]

您正在子目录中使用Silex:

http://localhost/mysite/index.php/about
因此,您必须调整.htaccess的重写基,请尝试以下操作:

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

您正在子目录中使用Silex:

http://localhost/mysite/index.php/about
因此,您必须调整.htaccess的重写基,请尝试以下操作:

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

问题是在Apache中处于重写模式。我更改了Apache默认配置->“AllowOverride All”

http://www.jarrodoberto.com/articles/2011/11/enabling-mod-rewrite-on-ubuntu


我添加了.htaccess文件。它正在工作,谢谢大家

问题是在Apache中处于重写模式。我更改了Apache默认配置->“AllowOverride All”

http://www.jarrodoberto.com/articles/2011/11/enabling-mod-rewrite-on-ubuntu


我添加了.htaccess文件。它正在工作,谢谢大家

非常感谢您的回复,但它给了我相同的错误“未找到此服务器上未找到请求的URL/mysite/about”。我认为。htaccess不工作。的任何内容都没有更改。htaccess可能需要在apache配置中进行一些更改?可能是apache重写模块未启用,或.htaccess文件是不允许的(即,
AllowOverride All
未在主Apache配置中设置)。非常感谢您的回复,但它给了我相同的错误“未找到请求的URL/mysite/about未在此服务器上找到”我认为.htaccess不起作用。htaccess的任何内容都没有更改。可能需要在apache配置中进行一些更改?可能是apache重写模块未启用,或者.htaccess文件不被允许(即,
AllowOverride All
未在主apache配置中设置)