【发布时间】:2013-11-05 15:59:43
【问题描述】:
我有一个使用 Angularjs 和 Symfony 2 开发的应用程序,我启用了 html5 模式以获取友好的 url。
该应用程序与 Symfony 2.3 集成以响应服务。
app.js
.config(['$routeProvider', '$locationProvider','$provide' , function($routeProvider, $locationProvider,$provide) {
$provide.decorator('$sniffer', function($delegate) {
$delegate.history = false;
return $delegate;
});
$routeProvider.when('/home', {templateUrl: 'views/home.html', controller: 'HomeController'});
$routeProvider.when('/quienes_somos', {templateUrl: 'views/quienes_somos.html', controller: 'QuienesSomosController'});
$routeProvider.when('/ubicanos', {templateUrl: 'views/ubicanos.html', controller: 'UbicanosController'});
$routeProvider.when('/ubicanos/:route', {templateUrl: 'views/ubicanos.html', controller: 'UbicanosController'});
$routeProvider.when('/catalogo', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController' });
$routeProvider.when('/catalogo/:category', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController' });
$routeProvider.when('/catalogo/:category/:productid', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController'});
$routeProvider.when('/catalogo/results',{templateUrl: 'views/catalogo.html', controller: 'CatalogoController'});
$routeProvider.when('/noticias', {templateUrl: 'views/noticias.html', controller: 'NoticiasController'});
$routeProvider.otherwise({redirectTo: '/home'});
$locationProvider.html5Mode(true);
}]);
当我尝试直接访问放置类别的路由和参数时出现问题。
Angularjs 不加载。但其他路线工作正常。
不工作的路线
$routeProvider.when('/catalogo/:category', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController' });
$routeProvider.when('/catalogo/:category/:productid', {templateUrl: 'views/catalogo.html', controller: 'CatalogoController'});
我也在 index.html <base href="/index.html" /> 上设置了这个
这是.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
我已对 htaccess 进行了修改以使其正常工作,但并不幸运。它回滚了。
有什么想法吗?请。 谢谢。
【问题讨论】:
-
我最近遇到了一个参数不工作的路由问题。当我将它从 /foo/:id 更改为 /foo/:id/bar 时它开始工作 - 不知道为什么:)
-
你好@aweibell 上周当我将所有 index.html 内容更改为 Symfony View .twig 时,问题解决了,出现路由冲突并且 Htaccess 无法正常工作。现在它正在工作。谢谢
标签: javascript php .htaccess angularjs symfony