开发者

htaccess rewrite and recursive internal redirects

开发者 https://www.devze.com 2023-01-31 05:23 出处:网络
I want to do a simple internal htaccess rewrite which is http://localhost/icore4/t9/module/ac/Main.php?do=subject_add

I want to do a simple internal htaccess rewrite which is

http://localhost/icore4/t9/module/ac/Main.php?do=subject_add

to

http://localhost/icore4/module/ac/Main.php?do=subject_add

I am using the following rewrite rule

RewriteEngine on
RewriteRule ^([A-Za-z0-9]*/)(.*)$ $2 [NC,L]

I keep getting page not found error.

When I look at the rewrite log I see that the rewriting is happening recursively. That is

http://localhost/icore4/t9/module/ac/Main.php?do=subject_add

to

http://localhost/icore4/module/ac/Main.php?do=subject_add

to

http://localhost/icore4/ac/Main.php?do=subject_add

to

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 p开发者_如何学编程refix: 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


I think this recursion is supposed to happen.

After the url goes through the rewrite rule, it is again passed to the mod_rewrite engine with the same htaccess. In you case it will always satisfy the Reg exp.

You may put a rewrite cond to avoid the same, something like

RewriteEngine on
RewriteCond %{QUERY_STRING} !t=(.*)
RewriteRule ^([A-Za-z0-9_-]*/)(.*)$ $2?%{QUERY_STRING}&t=$1 [NC,L]


Use a stricter pattern if you can, like for example limiting the first segment to two characters:

RewriteRule ^[A-Za-z0-9]{2}/(.+) $1 [L]

Or by specifying the number of following segments:

RewriteRule ^[A-Za-z0-9]+/([^/]+/[^/]+/[^/]+)$ $1 [L]
0

精彩评论

暂无评论...
验证码 换一张
取 消