Forum Moderators: phranque

Message Too Old, No Replies

rewrite url

         

webnoob

12:05 pm on May 17, 2005 (gmt 0)

10+ Year Member



i need this url:

/info.php?id=1&p=2

to:

/info/1/2 (p=2 won't always be in the url)

this is what i came up with:

RewriteRule ^info/([0-9]+)/([0-9]+) /info.php?id=$1&p=$2 [L]

is this right?
also after rewritten to: /info/1/2 how do i let the rewrite accept a query string, ie:

/info/1/2?something=else

thanks.

jdMorgan

1:02 pm on May 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are actually rewriting /info/1/2 to /info.php?id=1&p=2, and this is the usual procedure. See this recent thread for more: [webmasterworld.com...]

Your code as-is will pass through any query string appended to /info/1/2 without any changes.

However, if "/2" may not be present in the requested URL, you'll need to allow for that in the rule:


RewriteRule ^info/([0-9]+)(/([0-9]+))?/?$ /info.php?id=$1&p=$3 [L]

This also allows for an optional trailing slash, as added by some clients.

Jim

webnoob

1:57 pm on May 17, 2005 (gmt 0)

10+ Year Member



is $3 a typo? shouldn't it be $2?
still new to rewrite so excuse me if that is correct.

jdMorgan

8:10 pm on May 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> is $3 a typo? shouldn't it be $2?

No, count the left parentheses.

Jim

webnoob

1:52 pm on May 18, 2005 (gmt 0)

10+ Year Member



i've tried the rewrite code you posted, but it doesn't work. no errors, just returns a blank white page when i try visit /info/1 (with/without trailing slash).

alexo

12:22 am on May 20, 2005 (gmt 0)

10+ Year Member



Hello

how can i redirect[301] only 1 dinamic page to another.

like this
more.php?id=7710_0_14_0_C
to
more.php?id=1110_0_14_0_C

i try to do this, as i did for static pages, but it don't work :=-(

thx

jdMorgan

3:06 am on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alexo,

See RewriteCond [httpd.apache.org] %{QUERY_STRING} for more info.

Jim

jdMorgan

3:11 am on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



webnoob,

"/info/1" should be rewritten to "/info.php?id=1&p=" by the rule.

What happens if you type "htttp://example.com/info.php?id=1&p=" into your browser?

Jim

alexo

12:11 am on May 22, 2005 (gmt 0)

10+ Year Member



<See RewriteCond %{QUERY_STRING} for more info.>

i'm sorry, but i don't understand nothing there.
btw., on the other forum, i got the answer that is't impossible.
is it right?

thx

jdMorgan

1:26 am on May 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Other forum? No wonder. :)

I hope you have reviewed the documents cited in our forum charter [webmasterworld.com]. If not, you may not be able to get this to work. The chance of success is low if you don't understand how the code works.


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=7710_0_14_0_C$
RewriteRule ^more\.php$ http://www.example.com/more.php?id=1110_0_14_0_C [R=301,L]

Jim

alexo

1:56 am on May 22, 2005 (gmt 0)

10+ Year Member



waw ... it's works

thank you very much