我的routing.yml文件中有一个简单的重定向:
products_in_categories:
path: /{slug}
defaults: { _controller: MpShopBundle:Category:show }
redirect_category:
path: /112-redirect-this
defaults:
_controller: MpShopBundle:Category:show
route: products_in_categories
slug: to-this
permanent: true
所以当我转到localhost/web/app_dev.php/112-redirect-this
时,它应该执行301重定向并更改网址...它会成功加载页面,但网址不会更改。它显示:
localhost/web/app_dev.php/112-redirect-this
何时显示:
localhost/web/app_dev.php/to-this
我做错了吗?
答案 0 :(得分:2)
根据Symfony文档,您的重定向路线应指向internal sealed class EntityFrameworkRepository<TEntity> : IEntityWriter<TEntity>, IEntityReader<TEntity> where TEntity : Entity
{
private readonly Func<DbContext> _contextProvider;
public EntityFrameworkRepository(Func<DbContext> contextProvider)
{
_contextProvider = contextProvider;
}
public IQueryable<TEntity> Query()
{
var context = _contextProvider();
return context.Set<TEntity>().AsNoTracking();
}
// Methods removed for brevity
}
操作:
FrameworkBundle:Redirect:redirect
此处描述:http://symfony.com/doc/current/routing/redirect_in_config.html#redirecting-using-a-route