1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Yet another mod_rewrite question

Discussion in 'Apache' started by dj1471, Nov 13, 2005.

  1. #1
    Wow, it seems this forum is full of mod_rewrite questions - sorry to add yet another ;-)

    I've got a load of URLs with query strings which I need to redirect to pages with completely different names (i.e. the name is not directly related to the query string).

    For example:
    /modules.php?name=whatever&op=load&file=blah

    would need to redirect to:
    /someotherpage123.html

    I have ~2000 similar URLs, all of which need to be redirected to a different page. The whole filename and query string is needed to determine which page to redirect to.

    I've spent hours Googling and trying different things, but just can't figure it out. I would have thought it would be simple, as no regular expressions should be needed...

    Thanks in advance for any help!
     
    dj1471, Nov 13, 2005 IP
  2. suzigeek

    suzigeek Peon

    Messages:
    142
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is there anything in the query string that would relate/match your static urls?

    If so then you have a good chance of writing a rule to redirect fairly easily.
     
    suzigeek, Nov 13, 2005 IP
  3. dj1471

    dj1471 Well-Known Member

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    #3
    Unfortunately not - I'll need an individual rule for every URL.
     
    dj1471, Nov 13, 2005 IP
  4. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    johnt, Nov 14, 2005 IP
  5. dj1471

    dj1471 Well-Known Member

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    #5
    Can RewriteMap be used in .htaccess files? I'm getting 'RewriteMap not allowed here' errors (AllowOverride is set to All). I don't have access to the configuration file of the server I'm working on, so I have to use .htaccess...
     
    dj1471, Nov 14, 2005 IP
  6. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #6
    As far as I'm aware you can use RewriteMap anywhere that you can use RewriteRule.
     
    johnt, Nov 14, 2005 IP
  7. dj1471

    dj1471 Well-Known Member

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    #7
    According to the docs I should have read eariler, RewriteMap can only be used in the server config or virtual host configs :(

    One thing I was trying earlier was:
    RewriteCond %{QUERY_STRING} name=whatever&op=load&file=blah
    RewriteRule ^someotherpage123.html [R=301,L]

    Might some variation of that work? It didn't when I tried, but I know a misplaced '^' or '/' can make all the difference...
     
    dj1471, Nov 14, 2005 IP
  8. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #8
    try
    RewriteCond %{QUERY_STRING} name=whatever&op=load&file=blah
    RewriteRule ^modules.php$ someotherpage123.html [R=301,L]
    Code (markup):
    I think that should do it.
     
    johnt, Nov 15, 2005 IP
    dj1471 likes this.
  9. dj1471

    dj1471 Well-Known Member

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    #9
    Yes!

    Thank you very much :)
     
    dj1471, Nov 15, 2005 IP