Forum Moderators: phranque

Message Too Old, No Replies

Difficult rewrite rule

         

riccardo83

4:14 am on May 27, 2007 (gmt 0)

10+ Year Member



hi guys,
at the moment i redirect this link:

http://www.example.com/topic,14063,.html
to this:
http://www.example.com/viewtopic.php?t=14063

by using

RewriteRule ^topic,([0-9]+),.html?$ viewtopic.php?t=$1 [L]

But how is it possible to rewrite

http://www.example.com/topic,17183,-fanvid.html
to
http://www.example.com/viewtopic.php?t=17183?

its like removing something what you dont know, -fanvid could be any other syntax...

[edited by: jdMorgan at 4:17 am (utc) on May 27, 2007]

jdMorgan

4:21 am on May 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure why you said this is difficult, but I'd suggest:

RewriteRule ^topic,([0-9]+),[b]-fanvid[/b]\.html$ viewtopic.php?t=$1 [L]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

riccardo83

4:29 am on May 27, 2007 (gmt 0)

10+ Year Member



the problem is its not always -fanvid, it could be anything...

riccardo83

5:10 am on May 27, 2007 (gmt 0)

10+ Year Member



please,

how can i include % in mod_rewrite?

this url
http://www.example.com/topic,11231,-games-discussion%.html

wont work with

RewriteRule ^topic,([0-9]+),([-A-Za-z0-9%-]+)\.html?$ viewtopic.php?t=$1 [L]

[edited by: jdMorgan at 7:33 pm (utc) on May 27, 2007]
[edit reason] example.com [/edit]

jdMorgan

2:38 pm on May 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> how can i include % in mod_rewrite?

One problem at a time, please...

You say that -fanvid "could be anything" -- Can you be more specific?
Is it always preceded by a comma? does it always start with "-"? Is it always there, or is it optional?

You need to fully define all possible variations in order to write a regular-expressions pattern to match.

Jim

g1smd

4:41 pm on May 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It is possible to strip off extra characters from a URL by (bracketing) all characters after the last one that you will know will always be there and then not reusing those characters in the new URL.