我想爲我的骨幹和苗條的Web應用程序配置htaccess。骨幹和苗條的框架重定向路由htacces
這裏是我的根網址:mysite.com/myproject/
這裏是我如何安排我的目錄:
server.php
,在這裏我使用超薄框架,定義我的 '路線'- 一個包含Slim框架的目錄叫做
data
- 一個目錄中包含我叫主幹應用
js
我願做一些像mysite.com/myproject/post
s到讓我的帖子的完整列表 或mysite.com/myproject/post/:id
得到一個職位
我知道,我可以使用重定向到「模擬」不存在的URL。 理論上,如果我嘗試mysite.com/posts
,Apache/.htaccess
重定向到server.php
我的「路線」按照我的要求做,並將我的結果返回給主幹。
但無論我嘗試過,似乎工作。
編輯
我已經找到解決方案的一部分。
我將htaccess和server.php文件移動到數據導演。
這裏是我的server.php文件
<?php
require_once("Slim/Slim.php");
$app = new Slim();
$app->get('/posts','getPosts');
$app->get('/post/:id','getPost');
$app->run();
function getPosts() { echo "Hello world, get post list"; }
function getPost($id) { echo "Hello world, get one post = ".$id; }
?>
這裏是我的骨幹收集聲明
window.PostList = Backbone.Collection.extend({
model : Post,
url:"data/posts",
initialize : function() {
console.log ("collection created.")
}
});
而且.htaccess文件
RewriteEngine On
RewriteBase /myproject/data
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ server.php [QSA,L]
在骨幹fetch method
,請求是發送到http://mysite.com/myproject/data/posts
,我可以看到響應到控制檯Hello world, get post list
但我不能要求像mysite/myproject/posts
哪些值爲RewriteBase
?其值爲backbone collection
?
通常,您將在Apache中配置'VirtualHost'指令,但虛擬主機配置無法在'.htaccess'中定義。你有權修改服務器配置('httpd.conf')嗎?請參閱:http://httpd.apache.org/docs/2.2/vhosts/examples.html – jevakallio
thk的答覆,但沒有我不能訪問httpd.conf.i'm試試這個因爲我跟隨這個答案http ://bit.ly/qVSQgx在stackoverflow – akio
而我正在使用這個教程http://bit.ly/Zdb3Iv並用主幹的CRUD方法替換jquery ajax調用。 – akio