Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php .htaccess重写规则到主干路由器转换_Php_Javascript_.htaccess_Mod Rewrite_Backbone.js - Fatal编程技术网

Php .htaccess重写规则到主干路由器转换

Php .htaccess重写规则到主干路由器转换,php,javascript,.htaccess,mod-rewrite,backbone.js,Php,Javascript,.htaccess,Mod Rewrite,Backbone.js,我在互联网上做了一些挖掘,但没有什么能让自己变得明显 我希望将定制的CMS与主干网集成在一起,这样就可以使用原始http请求或通过主干网中处于“状态”的交换机加载页面。CMS目前专注于通过htaccess/mod rewrite为其路由/URL自动重写规则,但主干网对其内部路由使用不同的格式结构 我希望CMS能够将它的重写规则转换成主干格式,这样每当一个页面被添加到CMS时,主干就会意识到它并自动更新自己。例如,CMS向全局站点地图对象输出这样的页面负载: .... "contact"

我在互联网上做了一些挖掘,但没有什么能让自己变得明显

我希望将定制的CMS与主干网集成在一起,这样就可以使用原始http请求或通过主干网中处于“状态”的交换机加载页面。CMS目前专注于通过htaccess/mod rewrite为其路由/URL自动重写规则,但主干网对其内部路由使用不同的格式结构

我希望CMS能够将它的重写规则转换成主干格式,这样每当一个页面被添加到CMS时,主干就会意识到它并自动更新自己。例如,CMS向全局站点地图对象输出这样的页面负载:

....
"contact"       => array(
        "key"       =>      "contact",
        "url"       =>      "^(en|fr|de)/contact/$",
        "type"      =>      "page",
        "template"  =>      "contact",
        "method"    =>      "contact",
        "sitemap"   =>      TRUE,
        //other page config vars etc
    ),//..and so on
...
然后有一个解析器将规则写入.htaccess,如下所示:

RewriteRule ^(en|fr|de)/contact$ index.php?page=contact&lang=$1&section=$2
问题:

很明显,这有点不同,需要在PHP中进行大量的翻译工作才能输出一个干净的路由器配置。 我不敢相信我是第一个遇到这种情况的人,因为这似乎是尝试将主干应用程序集成到CMS的必要步骤。有人能告诉我翻译这些字符串格式的方法吗?也许我用了错误的方法


非常感谢。

主干网支持使用该方法将路由定义为正则表达式。Apache mod_重写规则也是正则表达式。因此,诸如
^(en | fr | de)/contact/$
之类的表达式已经是有效的主干路由

您不会说您是否已经有了一种机制,可以通过“站点地图”服务或通过将数据引导到服务器上的HTML页面来获取到客户端的路由配置。但是,假设您可以像这样输出站点地图对象:

var sitemap = {
  "contact": {
    "url": "^(en|fr|de)/contact/$",
    "type": "page"
    //..other properties
   },
   //...other pages
}
您可以通过迭代站点地图来注册路由:

var CMSRouter = Backbone.Router.extend({
  page: function(pageName, language) {
      console.log(pageName); // -> "contact"
      console.log(language); // -> "en"
  }
});

var router = new CMSRouter();
_.each(sitemap, function(entry, key) {
    //handler method based on type ("page")
    var handler = router[entry.type];

    //create a pre-applied callback function where the first argument
    //is always set to the sitemap entry key ("contact"), and the
    //rest of the arguments are filled from the capturing groups from
    //the regular expression.
    var callback = _.bind(handler, router, key);

    //register route
    router.route(new RegExp(entry.route), callback);
});

Backbone.history.start();

这可能没有考虑到系统的许多复杂性,但原则上它应该工作得很好。如果您能以更准确的要求编辑您的问题,我很乐意编辑答案。

主干网支持使用该方法将路由定义为正则表达式。Apache mod_重写规则也是正则表达式。因此,诸如
^(en | fr | de)/contact/$
之类的表达式已经是有效的主干路由

您不会说您是否已经有了一种机制,可以通过“站点地图”服务或通过将数据引导到服务器上的HTML页面来获取到客户端的路由配置。但是,假设您可以像这样输出站点地图对象:

var sitemap = {
  "contact": {
    "url": "^(en|fr|de)/contact/$",
    "type": "page"
    //..other properties
   },
   //...other pages
}
您可以通过迭代站点地图来注册路由:

var CMSRouter = Backbone.Router.extend({
  page: function(pageName, language) {
      console.log(pageName); // -> "contact"
      console.log(language); // -> "en"
  }
});

var router = new CMSRouter();
_.each(sitemap, function(entry, key) {
    //handler method based on type ("page")
    var handler = router[entry.type];

    //create a pre-applied callback function where the first argument
    //is always set to the sitemap entry key ("contact"), and the
    //rest of the arguments are filled from the capturing groups from
    //the regular expression.
    var callback = _.bind(handler, router, key);

    //register route
    router.route(new RegExp(entry.route), callback);
});

Backbone.history.start();

这可能没有考虑到系统的许多复杂性,但原则上它应该工作得很好。如果你能以更准确的要求编辑你的问题,我很乐意编辑答案。

wow。。我是否完全错过了主干可以使用正则表达式进行路由!!这是新的吗?谢谢你我来试试我太笨了。。我可以发誓,情况并非总是这样。。文档的第一行。。。非常感谢。哇!我是否完全错过了主干可以使用正则表达式进行路由!!这是新的吗?谢谢你我来试试我太笨了。。我可以发誓,情况并非总是这样。。文档的第一行。。。非常感谢。