我有两个类似于此示例的 codeigniter 应用程序。我已经创建了两个index.php
文件,如示例所述(第二个文件名为 oglasnik.php)。我想调用没有调用所需应用程序的文件名的应用程序。
我以此为例。所以我现在的 .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 Found,不应该这条规则:
RewriteRule ^oglasnik$ oglasnik.php [L]
将其重写为 oglasnik.php。当我去 oglasnik.php 它工作正常。
我也很想知道这个路由是如何工作的。重写的 url 是否再次访问 .htacces 文件,这是我在这个答案中看到的。
重写日志:
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