1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mod rewrite help needed

Discussion in 'PHP & Perl' started by kalekom, May 21, 2009.

  1. kalekom

    kalekom Junior Member

    Joined:
    Jul 25, 2008
    Messages:
    172
    Likes Received:
    356
    Occupation:
    CEO - SEO
    Location:
    here
    Home Page:
    I have a small problem with redirecting.

    I would like to redirect visitors from this aadress:

    Code:
    http://mysite.com/modules.php?name=Services
    to

    Code:
    http://mysite.com/something/
    I currently have tried:

    Code:
    RewriteEngine ON
    
    RewriteRule   ^modules\.php?name=Services$ http://www.mysite.com/something/ [R=301,L]
    
    
    
    but no luck...

    Hope that someone can help.

    Thanks.
     
  2. purebackend

    purebackend Newbie

    Joined:
    May 10, 2009
    Messages:
    37
    Likes Received:
    46
    You can't just plain redirect on the query string, you have to add a RewriteCond such as

    Code:
    RewriteEngine On
    RewriteCond   %{QUERY_STRING} ^name=Services$
    RewriteRule   ^modules\.php$ hxxp://w3.mysite.com/something/ [R=301,L]
     
    • Thanks Thanks x 2
  3. kalekom

    kalekom Junior Member

    Joined:
    Jul 25, 2008
    Messages:
    172
    Likes Received:
    356
    Occupation:
    CEO - SEO
    Location:
    here
    Home Page:
    Thanks, but this also passes query string to my new address. How to avoid that?
     
  4. neobyte

    neobyte Junior Member

    Joined:
    Sep 15, 2008
    Messages:
    122
    Likes Received:
    16
  5. kalekom

    kalekom Junior Member

    Joined:
    Jul 25, 2008
    Messages:
    172
    Likes Received:
    356
    Occupation:
    CEO - SEO
    Location:
    here
    Home Page:
    Thanks, but this is not working at all...


     
  6. _Austin

    _Austin Junior Member

    Joined:
    Apr 9, 2009
    Messages:
    147
    Likes Received:
    39
    Let me know if this works for you:

    Code:
    RewriteEngine On
    RewriteRule ^contact$ modules.php?name=Services [L]

    _Austin
     
  7. kalekom

    kalekom Junior Member

    Joined:
    Jul 25, 2008
    Messages:
    172
    Likes Received:
    356
    Occupation:
    CEO - SEO
    Location:
    here
    Home Page:
    Thanks for trying Austin!

    I have basic understanding how mod_rewrite works and this is not what I'm looking for.

    Solution posted by purebackend works but it also sends query string (?name=Services) to new address that it will become http://mysite.com/something/?name=Services. I would just like to send visitors from

    Code:
    http://mysite.com/modules.php?name=Services
    
    to
    
    http://mysite.com/something/



     
  8. BlackMelvyn

    BlackMelvyn Regular Member

    Joined:
    Jul 8, 2008
    Messages:
    202
    Likes Received:
    272
    Home Page:
    Try this
    Code:
    RewriteEngine On
    RewriteCond   %{QUERY_STRING} ^name=Services$
    RewriteRule   modules\.php /something/ [R=301,L]
     
  9. kalekom

    kalekom Junior Member

    Joined:
    Jul 25, 2008
    Messages:
    172
    Likes Received:
    356
    Occupation:
    CEO - SEO
    Location:
    here
    Home Page:
    Also passes query string name=Services so visitors will be redirected to www.mysite.com/something/?name=Services
     
  10. BlackMelvyn

    BlackMelvyn Regular Member

    Joined:
    Jul 8, 2008
    Messages:
    202
    Likes Received:
    272
    Home Page:
    what about this
    Code:
    RewriteEngine On
    RewriteCond   %{QUERY_STRING} ^name=Services$
    RewriteRule   modules\.php /something/? [R=301,L]
    It will force query string to be null
     
    • Thanks Thanks x 1
  11. kalekom

    kalekom Junior Member

    Joined:
    Jul 25, 2008
    Messages:
    172
    Likes Received:
    356
    Occupation:
    CEO - SEO
    Location:
    here
    Home Page:
    Thanks, this works ok.