使用.htaccess在codeigniter中路由到两个不同的应用程序

时间:2013-01-30 08:32:20

标签: php .htaccess codeigniter mod-rewrite

我有两个与此example类似的codeigniter应用程序。我创建了两个index.php文件,如示例所示(第二个文件名为oglasnik.php)。我想调用没有调用所需应用程序的文件名称的应用程序。

我以this为例。所以我现在的.htaccess文件是:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /PublishWall/
    DirectoryIndex indexl.php

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ indexl.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ indexl.php?/$1 [L]

    RewriteCond $1 !^(indexl\.php|oglasnik\.php|images|robots\.txt)
    RewriteRule ^oglasnik$ oglasnik.php [L]

 </IfModule>

 <IfModule !mod_rewrite.c>

    ErrorDocument 404 /index.php
 </IfModule> 
php_value date.timezone "Europe/Ljubljana"
AddDefaultCharset utf-8

当我路线到oglasnik时,我得到404 Page Not Not Found,不应该这样:

RewriteRule ^oglasnik$ oglasnik.php [L]

将其重写为oglasnik.php。当我去oglasnik.php它工作正常。

另外,我很想知道这种路由是如何工作的。重写的网址是否会再次访问.htacces文件,这是我在this answer中看到的内容。

重写日志:

127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (3) [perdir C:/wamp/www/PublishWall/] strip per-dir prefix: C:/wamp/www/PublishWall/oglasnik -> oglasnik
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (3) [perdir C:/wamp/www/PublishWall/] applying pattern '^(.*)$' to uri 'oglasnik'
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (4) [perdir C:/wamp/www/PublishWall/] RewriteCond: input='/PublishWall/oglasnik' pattern='^system.*' => not-matched
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (3) [perdir C:/wamp/www/PublishWall/] strip per-dir prefix: C:/wamp/www/PublishWall/oglasnik -> oglasnik
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (3) [perdir C:/wamp/www/PublishWall/] applying pattern '^(.*)$' to uri 'oglasnik'
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (4) [perdir C:/wamp/www/PublishWall/] RewriteCond: input='oglasnik' pattern='!^(indexl\.php|oglasnik\.php|images|robots\.txt)' => matched
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (4) [perdir C:/wamp/www/PublishWall/] RewriteCond: input='/PublishWall/oglasnik' pattern='^application.*' => not-matched
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (3) [perdir C:/wamp/www/PublishWall/] strip per-dir prefix: C:/wamp/www/PublishWall/oglasnik -> oglasnik
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (3) [perdir C:/wamp/www/PublishWall/] applying pattern '^(oglasnik)$' to uri 'oglasnik'
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (2) [perdir C:/wamp/www/PublishWall/] rewrite 'oglasnik' -> 'oglasnik.php'
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (3) [perdir C:/wamp/www/PublishWall/] add per-dir prefix: oglasnik.php -> C:/wamp/www/PublishWall/oglasnik.php
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (2) [perdir C:/wamp/www/PublishWall/] trying to replace prefix C:/wamp/www/PublishWall/ with /PublishWall/
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (4) add subst prefix: oglasnik.php -> /PublishWall/oglasnik.php
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#15b10d8/initial] (1) [perdir C:/wamp/www/PublishWall/] internal redirect with /PublishWall/oglasnik.php [INTERNAL REDIRECT]
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#151b500/initial/redir#1] (3) [perdir C:/wamp/www/PublishWall/] strip per-dir prefix: C:/wamp/www/PublishWall/oglasnik.php -> oglasnik.php
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#151b500/initial/redir#1] (3) [perdir C:/wamp/www/PublishWall/] applying pattern '^(.*)$' to uri 'oglasnik.php'
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#151b500/initial/redir#1] (4) [perdir C:/wamp/www/PublishWall/] RewriteCond: input='/PublishWall/oglasnik.php' pattern='^system.*' => not-matched
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#151b500/initial/redir#1] (3) [perdir C:/wamp/www/PublishWall/] strip per-dir prefix: C:/wamp/www/PublishWall/oglasnik.php -> oglasnik.php
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#151b500/initial/redir#1] (3) [perdir C:/wamp/www/PublishWall/] applying pattern '^(.*)$' to uri 'oglasnik.php'
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#151b500/initial/redir#1] (4) [perdir C:/wamp/www/PublishWall/] RewriteCond: input='oglasnik.php' pattern='!^(indexl\.php|oglasnik\.php|images|robots\.txt)' => not-matched
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#151b500/initial/redir#1] (3) [perdir C:/wamp/www/PublishWall/] strip per-dir prefix: C:/wamp/www/PublishWall/oglasnik.php -> oglasnik.php
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#151b500/initial/redir#1] (3) [perdir C:/wamp/www/PublishWall/] applying pattern '^(oglasnik)$' to uri 'oglasnik.php'
127.0.0.1 - - [30/Jan/2013:23:35:36 +0100] [localhost/sid#991d38][rid#151b500/initial/redir#1] (1) [perdir C:/wamp/www/PublishWall/] pass through C:/wamp/www/PublishWall/oglasnik.php

1 个答案:

答案 0 :(得分:0)

您可能想尝试这个:

RewriteCond %{REQUEST_URI} !^(indexl\.php|oglasnik\.php|images|robots\.txt)
RewriteRule ^oglasnik.*$ oglasnik.php?/$1 [L]