2012-09-10 115 views
-1

我写了一条规则,将斜线后的所有内容重定向到index.php?section=site。此规则正常工作:htaccess不同路径的重写规则

RewriteRule (.*)(\/)? index.php?section=site 

如果URI /cms/....我想它重定向到index.php?section=cms。问题是第一条规则说,一切去index.php?section=site所以我怎么可以避免,如果该网址的开始是CMS?

我尝试这样:

RewriteRule (.*)(\/)? index.php?section=site 
RewriteRule cms\/(.*) index.php?section=cms [L] 

例如:

  1. 网址,如:?domain.com/login,属于index.php的部分=网站
  2. 网址如:domain.com/cms/login,属于index.php?section = cms
+0

逆转的重写规则的顺序。所以CMS规则是第一位的。 – Virendra

+0

尝试过,没有帮助 – user1403317

+0

尝试: 'RewriteRule cms /(.*)index.php?section = cms [L] RewriteRule(。*)(\ /)?的index.php?节= site' – Virendra

回答

1

如果这是您唯一的规则,您的目标是使用index.php作为Front-end Controller,我建议使用FallbackResource并使用PHP解析/路由请求。

FallbackResource /index.php 

在最后,它避免了mod_rewrite的开销和复杂度,可以说是提供了更大的灵活性。

0

我发现简单的解决方案因为我用htaccess尝试过的一切都没有奏效。

.htaccess文件:

RewriteRule (.*) index.php 

索引文件:

$uri = $_SERVER['REQUEST_URI']; 
$ex = explode("/",$uri); 
switch($ex[2]) 
{ 
    case "cms": 
     // cms dispatch here 
    break; 

    default: 
     // site dispatch here 
    break; 

} 

不管怎样,谢谢:)