.htaccess for pushstate支持的规则

时间:2015-06-28 17:36:56

标签: php angularjs .htaccess silex pushstate

我为服务器端启动了一个基于Angular.js和Silex的应用程序。

我会使用真实的URL(没有哈希),但它不起作用。

我已使用以下行激活了角度上的pushstate:

    $locationProvider.html5Mode(true);

但我不知道如何配置服务器。实际上,当我尝试访问localhost / test时,除了silex之外什么都没做。*没有为“GET / test”找到路由..

我的htaccess就像它:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php [L]

我的项目结构就像它一样

| --app /
| ---- app.php
| ----控制器/
| ------- MainController.php
| --web /
| ----的index.php
| ---- JS /
| --------- app.js
...

感谢您的帮助

编辑:

路线声明:

config(['$routeProvider, $locationProvider', function($routeProvider, $locationProvider) {

$locationProvider.html5Mode(true);

$routeProvider.when('/test',{
    templateUrl : '/cuisine',
    controller  : 'CookController'
});

}

2 个答案:

答案 0 :(得分:0)

我在我的网站上使用它,并且它的工作,请试一试。否则我建议你打开apache中的mod_rewrite登录并查看日志

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html

答案 1 :(得分:0)

你的问题在于 RewriteBase 。重写基础基于URI文件夹,您要求 / test 而非 / web / test ,所以你的重写基础应该是/

我只是在猜测,但我认为您的文档根目录是 / path / to / your / project / web (应该是这样,只有网页目录才是公开的! )所以你的.htaccess不应该有你的RewriteBase。