简体   繁体   中英

Cumulative mod_rewrite rules

I'm having trouble understanding the mod_rewrite condictions and rules workflow. despite reading this very nice tutorial http://craym.eu/tutoriels/referencement/url_rewriting.html. I can't perform the job I need :

here is my 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]

Here is what I'm searching for in that file :

  • second rule, the simplest one (it works when it is alone), All the time rewrite

    • www.example.com/foo -> www.example.com/index.php?/foo .
    • This is a codeigniter framework rule.

    .

  • the first rule in the file should rewrite :

    • www.example.com/entreprise -> www.example.com/feerie
    • and after that the second rule should rewrite
    • www.example.com/feerie -> www.example.com/index.php?/feerie

here what I have in the 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

Adding this to the beginning seems to work :

RewriteBase /

Here is the full file

<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>

Can someone explain that to me ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM