Need some help on URL redirecting using HTACCESS

Discussion in 'Apache' started by тнє Sufi, Sep 22, 2012.

  1. #1
    I am trying to redirect one dynamic URL to another static URL.

    I wish domain.com/directory/url.php?id=3 to redirect to domain.com/item3.php and domain.com/directory/url.php?id=4 to redirect to domain.com/item4.php. I also wish to keep all other pages (domain.com/directory/url.php?id=xx) to remain as it is. Is it possible by anyway?
    Both are same domain and on the same server.
     
    тнє Sufi, Sep 22, 2012 IP
  2. Steupz

    Steupz Peon

    Messages:
    917
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Should work if you simply redirect these two.

    RedirectMatch 301 ^/domain.com/directory/url.php?id=3 domain.com/item3.php
    RedirectMatch 301 ^/domain.com/directory/url.php?id=4 domain.com/item4.php
     
    Steupz, Sep 23, 2012 IP
  3. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. But it did not work. Anymore suggestions?

     
    тнє Sufi, Sep 24, 2012 IP
  4. Steupz

    Steupz Peon

    Messages:
    917
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What happened when you tried it?
     
    Steupz, Sep 25, 2012 IP
  5. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Nothing happened. It just did not redirect to the page and remained on the same page.

     
    тнє Sufi, Sep 25, 2012 IP
  6. RTHosting

    RTHosting Greenhorn

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    13
    #6
    301 Redirect. Here is the code:

    "
    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^domain.com [nc]
    rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]".

    Kind Regards,
    RTH.
     
    RTHosting, Sep 26, 2012 IP
  7. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sorry this is not a normal 301 redirection. It has query string, and that needs to be redirected.

     
    тнє Sufi, Sep 28, 2012 IP
  8. тнє Sufi

    тнє Sufi Peon

    Messages:
    391
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I figured it out using following codes:
    
    RewriteEngine On
    RewriteCond %{QUERY_STRING} ^id=3$
    RewriteRule ^url.php$ /item3.php? [L,R=301]
    
    Code (markup):
    Here main URL: domain.com/directory/url.php?id=3
    Redirected to: doamin.com/item3.php

    I put this code on the HTACCESS file in directory folder.
     
    тнє Sufi, Sep 28, 2012 IP