[Resolved] RewriteRule help

Discussion in 'General' started by diggs, Apr 6, 2010.

  1. diggs

    diggs New Member

    Hi there!

    I did some extensive searching on the forums here and was unable to find what I'm looking for. I'm hoping someone can point me in the right direction here. What I'm trying to accomplish I thought was pretty simple however it's proving to be a bit tougher than originally thought.

    What I'm trying to do is simply replace certain characters in the QUERY_STRING with a RewriteRule and then redirect to this filtered url.

    The behavior of this code does what I want it to do, however it does not include the QUERY_STRING which is what I need.
    Code:
    RewriteRule ^(.*)-(.*)$ /$1_$2 [N]
    Currently this rewrite rule will change:
    • this-file-test.php -> this_file_test.php

    What I need to do is:
    • this-file-test.php?t=this-is-a-test -> this-file-test.php?t=this_is_a_test

    I believe what I need to do is something like....
    Code:
    RewriteCond %{QUERY_STRING} ^/(.*)-(.*)$ 
    RewriteRule ^(.*)$ /%1_%2 [N]
    
    ...however the proper syntax to accomplish this is escaping me. (is it even possible?)

    My only option here is to use lsws rewrite or a .htaccess file. As much as I'd love to just do this in code which would be SO much easier, the code is written by a 3rd party developer and I do not have the ability to alter it due to our contract with them.

    Does anyone have any suggestions?

    Thanks in advance for any help on this.
    Last edited by a moderator: Apr 8, 2010
  2. NiteWave

    NiteWave Administrator

    following one works on my test machine:
    Code:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^(.*)-(.*)$  
    RewriteRule ^(.*)$ $1?%1_%2 [N]
    
  3. diggs

    diggs New Member

    Perfect! Thank you kindly :)

Share This Page