Need help with Mod_Rewrite

Discussion in 'Apache' started by JinRoh, Aug 2, 2007.

  1. #1
    Hello, I am trying to do some things with mod_rewrite, but I'm not very good at it.

    Now I have a Rule
    RewriteRule ^css/video/([0-9]+)/$ /?video=$1
    Code (markup):
    So /css/video/17/ actually uses /?video=17

    But, the problem is that I want visitors using old links to be redirected to the new URL (So , do the inverse thing, if an user enters /?video=17 to be redirected to /css/video/17/ ,that actually will use /?video=17 :D)

    Do you think is it possible to do that with Mod Rewrite? Or with PHP maybe?

    (I didn't know if this should be posted in PHP forum, because it may be done with PHP also, so I'll post it too there)
     
    JinRoh, Aug 2, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    RewriteRule ^css/video/([0-9]+)/$ /?video=$1 [L]
    RewriteCond %{QUERY_STRING} ^video=([0-9]+)
    RewriteRule .* /css/video/%1/ [R=301,L]
    Code (markup):
    I hope that's right (and doesn't result in an infinite loop :p)
     
    krt, Aug 2, 2007 IP
  3. JinRoh

    JinRoh Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, but it was an infinite loop :p Didn't work :(
     
    JinRoh, Aug 3, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    What was I thinking? :D
    RewriteRule ^css/video/([0-9]+)/$ /?video=$1 [L]
    RewriteCond %{REQUEST_URI} \?video=([0-9]+)$
    RewriteRule .* /css/video/%1/ [R=301,L]
    Code (markup):
     
    krt, Aug 4, 2007 IP