mod_rewrite 代码有问题

mod_rewrite 代码有问题

我想将我的链接从 更改usercp.php?do=our_pics&p=$iusercp/our_pics/1

我有这个.htaccess 代码

RewriteEngine On
RewriteRule usercp/(.*)/(.*) usercp.php?do=$1&p=$2

问题当我使用分页将页面更改为另一个页面时,它会重定向到主页或第 1 页,这是因为 mod_rewrite 代码存在问题。

“编辑 1”

启用RewriteLog和RewriteLogLevel 2后,以下是问题发生时rewrite.log文件的内容。

127.0.0.1 - - [06/Jan/2013:20:37:26 +0200] [localhost/sid#6828d0][rid#ec2180/initial] (2) [perdir C:/Program Files/wamp/www/ebdaa_v3/] rewrite 'usercp/our_pics/3' -> 'usercp.php?do=our_pics/3'

127.0.0.1 - - [06/Jan/2013:20:37:26 +0200] [localhost/sid#6828d0][rid#ec2180/initial] (2) [perdir C:/Program Files/wamp/www/ebdaa_v3/] strip document_root prefix: C:/Program Files/wamp/www/ebdaa_v3/usercp.php -> /ebdaa_v3/usercp.php

127.0.0.1 - - [06/Jan/2013:20:37:26 +0200] [localhost/sid#6828d0][rid#ec2180/initial] (1) [perdir C:/Program Files/wamp/www/ebdaa_v3/] internal redirect with /ebdaa_v3/usercp.php [INTERNAL REDIRECT]

127.0.0.1 - - [06/Jan/2013:20:37:26 +0200] [localhost/sid#6828d0][rid#724160/initial/redir#1] (1) [perdir C:/Program Files/wamp/www/ebdaa_v3/] pass through C:/Program Files/wamp/www/ebdaa_v3/usercp.php

127.0.0.1 - - [06/Jan/2013:20:37:26 +0200] [localhost/sid#6828d0][rid#ec6190/initial] (2) [perdir C:/Program Files/wamp/www/ebdaa_v3/] rewrite 'usercp/mainpage' -> 'usercp.php?do=mainpage'

127.0.0.1 - - [06/Jan/2013:20:37:26 +0200] [localhost/sid#6828d0][rid#ec6190/initial] (2) [perdir C:/Program Files/wamp/www/ebdaa_v3/] strip document_root prefix: C:/Program Files/wamp/www/ebdaa_v3/usercp.php -> /ebdaa_v3/usercp.php

127.0.0.1 - - [06/Jan/2013:20:37:26 +0200] [localhost/sid#6828d0][rid#ec6190/initial] (1) [perdir C:/Program Files/wamp/www/ebdaa_v3/] internal redirect with /ebdaa_v3/usercp.php [INTERNAL REDIRECT]

127.0.0.1 - - [06/Jan/2013:20:37:26 +0200] [localhost/sid#6828d0][rid#727158/initial/redir#1] (1) [perdir C:/Program Files/wamp/www/ebdaa_v3/] pass through C:/Program Files/wamp/www/ebdaa_v3/usercp.php

答案1

打开你的RewriteLog,看看是什么出了问题。

RewriteLog /path/to/log
RewriteLogLevel 2

这将为您提供 mod_rewrite 所采取的每个步骤的详细信息,以便您可以看到逻辑上哪里出了问题。

答案2

如果我理解正确的话,您需要重写从usercp.php?do=our_pics&p=$i到 read 的链接usercp/our_pics/1。如果是这样,您可以尝试以下重写规则:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^do=(.*)&p=([0-9]*)$
RewriteRule usercp\.php$ /usercp/%1/%2? [R=302,L]

看来我没理解好你的问题,你问题中的例子不符合你的重写规则,如果你想反方向重写,可以试试这个块:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/usercp/(.*)/([0-9]*)$
RewriteRule .* /usercp.php?do=%1&p=%2 [R=302,L]

这会将 URL 从 转换usercp.php?do=our_pics&p=$iusercp/our_pics/1

相关内容