累积mod_rewrite规则

时间:2014-10-30 16:40:18

标签: php apache .htaccess mod-rewrite url-rewriting

我无法理解mod_rewrite condictions和规则工作流程。 尽管阅读了这篇非常好的教程http://craym.eu/tutoriels/referencement/url_rewriting.html.,但我无法完成我需要的工作:

这是我的htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^entreprise(.*)$ feerie$1


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

以下是我在该文件中搜索的内容:

  • 第二条规则,最简单的一条(单独使用时),一直重写

    • www.example.com/foo -> www.example.com/index.php?/foo
    • 这是一个codeigniter框架规则。

  • 文件中的第一条规则应该重写:

    • www.example.com/entreprise -> www.example.com/feerie
    • 之后第二条规则应重写
    • www.example.com/feerie -> www.example.com/index.php?/feerie

这里是我在rewrite.log中的内容:

127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (2) init rewrite engine with requested uri /entreprise
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (1) pass through /entreprise
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (3) [perdir C:/Users/NICOLAS/example/] strip per-dir prefix: C:/Users/NICOLAS/example/entreprise -> entreprise
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (3) [perdir C:/Users/NICOLAS/example/] applying pattern '^entreprise(.*)$' to uri 'entreprise'
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (2) [perdir C:/Users/NICOLAS/example/] rewrite 'entreprise' -> 'feerie'
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (3) [perdir C:/Users/NICOLAS/example/] add per-dir prefix: feerie -> C:/Users/NICOLAS/example/feerie
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (3) [perdir C:/Users/NICOLAS/example/] strip per-dir prefix: C:/Users/NICOLAS/example/feerie -> feerie
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (3) [perdir C:/Users/NICOLAS/example/] applying pattern '^(.*)$' to uri 'feerie'
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (2) [perdir C:/Users/NICOLAS/example/] rewrite 'feerie' -> 'index.php?/feerie'
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (3) split uri=index.php?/feerie -> uri=index.php, args=/feerie
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (3) [perdir C:/Users/NICOLAS/example/] add per-dir prefix: index.php -> C:/Users/NICOLAS/example/index.php
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (2) [perdir C:/Users/NICOLAS/example/] strip document_root prefix: C:/Users/NICOLAS/example/index.php -> /index.php
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#e4a8f0/initial] (1) [perdir C:/Users/NICOLAS/example/] internal redirect with /index.php [INTERNAL REDIRECT]
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#ea49b0/initial/redir#1] (2) init rewrite engine with requested uri /index.php
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#ea49b0/initial/redir#1] (1) pass through /index.php
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#ea49b0/initial/redir#1] (3) [perdir C:/Users/NICOLAS/example/] strip per-dir prefix: C:/Users/NICOLAS/example/index.php -> index.php
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#ea49b0/initial/redir#1] (3) [perdir C:/Users/NICOLAS/example/] applying pattern '^entreprise(.*)$' to uri 'index.php'
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#ea49b0/initial/redir#1] (3) [perdir C:/Users/NICOLAS/example/] strip per-dir prefix: C:/Users/NICOLAS/example/index.php -> index.php
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#ea49b0/initial/redir#1] (3) [perdir C:/Users/NICOLAS/example/] applying pattern '^(.*)$' to uri 'index.php'
127.0.0.1 - - [30/Oct/2014:17:46:49 +0100] [www.example.com/sid#b73910][rid#ea49b0/initial/redir#1] (1) [perdir C:/Users/NICOLAS/example/] pass through C:/Users/NICOLAS/example/index.php

1 个答案:

答案 0 :(得分:0)

将此添加到开头似乎有效:

RewriteBase /

这是完整的文件

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^entreprise(.*)$ index.php?/feerie$1 [R,L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]


</IfModule>

有人可以向我解释一下吗?