Forum Moderators: phranque

Message Too Old, No Replies

Need help redirect one page to another site

need help to redirect a specific page to another site

         

colombo

9:16 pm on Apr 30, 2010 (gmt 0)

10+ Year Member



Hello,
Here is the description on the final result that i need:

redirecting
  • http://www.domain_1.com/somepage.html?id=3

    to
  • http://www.domain_2.com/directory

    here is the code that i tried:

    Redirect 301 /somepage.html?id=3 [domain_2.com...]

    But it's not working, all i need is to redirect that page to a different url.

    Please advise.

    thanks.
  • Demaestro

    9:50 pm on Apr 30, 2010 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    Try this in an htaccess file in the root of your site.

    redirect /~domain_1.com/somepage.html?id=3 http:slashslashwww.domain_2.com/directory

    REPLACE slashslash with //

    I just did that so this forum doesn't link it.

    g1smd

    10:23 pm on Apr 30, 2010 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    You'll need a RewriteRule with [R=301,L] flags for this, and you can test the QUERY_STRING in a preceding RewriteCond.

    colombo

    10:51 pm on Apr 30, 2010 (gmt 0)

    10+ Year Member



    Thank you for the answers.
    Demaesto - i tried it, it doesn't work,i tried that code:
    Redirect 301 /~domain_1.com/somepage.html?id=3 http:slashslashwww.domain_2.com/directory

    g1smd - i didn't understand your answer, can you show me an example please?

    Demaestro

    11:14 pm on Apr 30, 2010 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    colombo what is your server OS and what are you using to serve files? Apache or IIS?

    Also I assume you replaced the slashslash

    colombo

    11:28 pm on Apr 30, 2010 (gmt 0)

    10+ Year Member



    I use Apache , not sure about the OS.

    Yes sure i replaced the domains and the slashslash.

    jdMorgan

    11:47 pm on Apr 30, 2010 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Some of the 833 previous threads [google.com] on this subject may be helpful.

    See the links to useful resources in our Apache Forum Charter.

    Please post specific questions back here.

    Jim

    colombo

    12:06 am on May 1, 2010 (gmt 0)

    10+ Year Member



    Thank you Jim.
    I saw your answer here - [webmasterworld.com...]

    i tried this code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} ^id=80564(&|$)
    RewriteRule ^product\.jhtm$ http://www.example.com/directory [R=301,L]

    It works , but i have only one problem now, it's redirect to:
    http://www.example.com/directory?id=80564

    and i want it to redirect to :
    http://www.example.com/directory

    i don't want it to pass the ID.

    Thanks for the help.

    [edited by: jdMorgan at 2:37 am (utc) on May 1, 2010]
    [edit reason] example.com [/edit]

    jdMorgan

    2:46 am on May 1, 2010 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    I don't know why you're checking your disk (twice) for file- and directory-exists. If you're not absolutely sure you need to do this, then don't do it -- Your site will be faster and your hard drive will last longer...

    The only way REQUEST_FILENAME won't resolve to an existing file is if you delete /product.jhtm
    So the rule will not run until you delete that file.

    If you must check -f and -d, then these two RewriteConds should be the very last ones, so they will only execute if absolutely necessary -- Put the query string check first.

    I suspect that all you need is this:

    RewriteEngine on
    #
    RewriteCond %{QUERY_STRING} ^id=80564(&.*)?$
    RewriteRule ^product\.jhtm$ http://www.example.com/directo[b]ry?[/b] [R=301,L]

    Jim

    colombo

    9:25 am on May 1, 2010 (gmt 0)

    10+ Year Member



    It works great, thank you Jim.