我想做一个简单的内部htaccess重写,这是
http://localhost/icore4/t9/module/ac/Main.php?do=subject_add
到
http://localhost/icore4/module/ac/Main.php?do=subject_add
我使用以下重写规则
RewriteEngine on
RewriteRule ^([A-Za-z0-9]*/)(.*)$ $2 [NC,L]
我一直在找不到页面错误。
当我查看重写日志时,我发现重写是以递归方式进行的。 那是
http://localhost/icore4/t9/module/ac/Main.php?do=subject_add
到
http://localhost/icore4/module/ac/Main.php?do=subject_add
到
http://localhost/icore4/ac/Main.php?do=subject_add
到
http://localhost/icore4/Main.php?do=subject_add
LOG
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34ad8e8/initial] (1) pass through /icore4/t9/module/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34ad8e8/initial] (3) [perdir F:/xampp/htdocs/icore4/] add path info postfix: F:/xampp/htdocs/icore4/t9 -> F:/xampp/htdocs/icore4/t9/module/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34ad8e8/initial] (3) [perdir F:/xampp/htdocs/icore4/] strip per-dir prefix: F:/xampp/htdocs/icore4/t9/module/ac/Main.php -> t9/module/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34ad8e8/initial] (3) [perdir F:/xampp/htdocs/icore4/] applying pattern '^([A-Za-z0-9]*/)(.*)$' to uri 't9/module/ac/Main.php'
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34ad8e8/initial] (2) [perdir F:/xampp/htdocs/icore4/] rewrite 't9/module/ac/Main.php' -> 'module/ac/Main.php'
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34ad8e8/initial] (3) [perdir F:/xampp/htdocs/icore4/] add per-dir prefix: module/ac/Main.php -> F:/xampp/htdocs/icore4/module/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34ad8e8/initial] (2) [perdir F:/xampp/htdocs/icore4/] strip document_root prefix: F:/xampp/htdocs/icore4/module/ac/Main.php -> /icore4/module/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34ad8e8/initial] (1) [perdir F:/xampp/htdocs/icore4/] internal redirect with /icore4/module/ac/Main.php [INTERNAL REDIRECT]
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3481db8/initial/redir#1] (2) init rewrite engine with requested uri /icore4/module/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3481db8/initial/redir#1] (1) pass through /icore4/module/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3481db8/initial/redir#1] (3) [perdir F:/xampp/htdocs/icore4/] strip per-dir prefix: F:/xampp/htdocs/icore4/module/ac/Main.php -> module/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3481db8/initial/redir#1] (3) [perdir F:/xampp/htdocs/icore4/] applying pattern '^([A-Za-z0-9]*/)(.*)$' to uri 'module/ac/Main.php'
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3481db8/initial/redir#1] (2) [perdir F:/xampp/htdocs/icore4/] rewrite 'module/ac/Main.php' -> 'ac/Main.php'
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3481db8/initial/redir#1] (3) [perdir F:/xampp/htdocs/icore4/] add per-dir prefix: ac/Main.php -> F:/xampp/htdocs/icore4/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3481db8/initial/redir#1] (2) [perdir F:/xampp/htdocs/icore4/] strip document_root prefix: F:/xampp/htdocs/icore4/ac/Main.php -> /icore4/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3481db8/initial/redir#1] (1) [perdir F:/xampp/htdocs/icore4/] internal redirect with /icore4/ac/Main.php [INTERNAL REDIRECT]
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3487118/initial/redir#2] (2) init rewrite engine with requested uri /icore4/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3487118/initial/redir#2] (1) pass through /icore4/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3487118/initial/redir#2] (3) [perdir F:/xampp/htdocs/icore4/] add path info postfix: F:/xampp/htdocs/icore4/ac -> F:/xampp/htdocs/icore4/ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3487118/initial/redir#2] (3) [perdir F:/xampp/htdocs/icore4/] strip per-dir prefix: F:/xampp/htdocs/icore4/ac/Main.php -> ac/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3487118/initial/redir#2] (3) [perdir F:/xampp/htdocs/icore4/] applying pattern '^([A-Za-z0-9]*/)(.*)$' to uri 'ac/Main.php'
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3487118/initial/redir#2] (2) [perdir F:/xampp/htdocs/icore4/] rewrite 'ac/Main.php' -> 'Main.php'
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3487118/initial/redir#2] (3) [perdir F:/xampp/htdocs/icore4/] add per-dir prefix: Main.php -> F:/xampp/htdocs/icore4/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3487118/initial/redir#2] (2) [perdir F:/xampp/htdocs/icore4/] strip document_root prefix: F:/xampp/htdocs/icore4/Main.php -> /icore4/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#3487118/initial/redir#2] (1) [perdir F:/xampp/htdocs/icore4/] internal redirect with /icore4/Main.php [INTERNAL REDIRECT]
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34895f8/initial/redir#3] (2) init rewrite engine with requested uri /icore4/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34895f8/initial/redir#3] (1) pass through /icore4/Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34895f8/initial/redir#3] (3) [perdir F:/xampp/htdocs/icore4/] strip per-dir prefix: F:/xampp/htdocs/icore4/Main.php -> Main.php
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34895f8/initial/redir#3] (3) [perdir F:/xampp/htdocs/icore4/] applying pattern '^([A-Za-z0-9]*/)(.*)$' to uri 'Main.php'
127.0.0.1 - - [15/Dec/2010:12:57:17 +051800] [localhost/sid#93d158][rid#34895f8/initial/redir#3] (1) [perdir F:/xampp/htdocs/icore4/] pass through F:/xampp/htdocs/icore4/Main.php
答案 0 :(得分:3)
我认为这种递归应该发生。
在url通过重写规则后,它再次传递给具有相同htaccess的mod_rewrite引擎。在你的情况下,它将始终满足Reg exp。
您可以使用重写cond来避免相同,例如
RewriteEngine on
RewriteCond %{QUERY_STRING} !t=(.*)
RewriteRule ^([A-Za-z0-9_-]*/)(.*)$ $2?%{QUERY_STRING}&t=$1 [NC,L]
答案 1 :(得分:1)
如果可以,请使用更严格的模式,例如将第一个段限制为两个字符:
RewriteRule ^[A-Za-z0-9]{2}/(.+) $1 [L]
或者通过指定以下细分的数量:
RewriteRule ^[A-Za-z0-9]+/([^/]+/[^/]+/[^/]+)$ $1 [L]