Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to change my link from usercp.php?do=our_pics&p=$i to usercp/our_pics/1.

I have this .htaccess code

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

The problem is when I using the pagination to change the page to another, it doing redirect to main page or page 1, and that because there are problem in mod_rewrite code .

"Edit 1"

After enable RewriteLog and RewriteLogLevel 2, the following is the content of rewrite.log file When the problem occurs.

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
share|improve this question

2 Answers 2

Turn on your RewriteLog to find out what's breaking.

RewriteLog /path/to/log
RewriteLogLevel 2

This will give you details on each and every step that mod_rewrite is taking, so that you can see where the logic is going wrong.

share|improve this answer
    
Please see "Edit 1" in my question, that is the content of rewrite.log file When the problem occurs. –  Lion King Jan 6 '13 at 18:48

If I understand you well, you need to rewrite the link from usercp.php?do=our_pics&p=$i to read usercp/our_pics/1. If so, you can try the following rewrite rules:

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

It seems that I did not understand your question well. The example in your question is not consistent with your rewrite rule. If you want to do the rewrite in the opposite direction, you can try this block:

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

This should convert the URL from usercp.php?do=our_pics&p=$i to usercp/our_pics/1.

share|improve this answer
    
Thanks for answer, but still same the problem. I think the problem in usercp.php?(do=$1)&p=$2 the variable that inside the brackets (do=$1). the previous variable is doesn't reach to the page. –  Lion King Jan 6 '13 at 15:49
    
@LionKing: Have another look at my answer. –  Khaled Jan 7 '13 at 7:45
    
Thanks Khaled, but still the same problem (redirect to main page). –  Lion King Jan 7 '13 at 10:49
    
@LionKing: I tested both of these and they are working. –  Khaled Jan 7 '13 at 10:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.