Forum Moderators: phranque

Message Too Old, No Replies

redirect dynamic url to new dynamic url

Changing one variable in a dynamic url through mod-rewrite

         

jmino14

3:59 pm on Apr 19, 2010 (gmt 0)

10+ Year Member



I am new to the RewriteEngine and have not been able to find an answer to the following issue. I run an ecommerce site with an ever changing catalog of product skus. Our URLs are dynamic. The question is, what if I want to have a dynamic variable redirect to a different dynamic variable.

For instance, I want:

www.mydomain.com/product.jhtm?id=12345

to now go to:

www.mydomain.com/product.jhtm?id=78910

How can I do this through the .htaccess?

Thanks in advance.

jdMorgan

4:11 pm on Apr 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



  • Use Apache mod_rewrite.
  • Use a RewriteCond pattern to match the query string.
  • Use the RewriteRule pattern to match the product.jhtm URL-path.
  • Put the protocol, domain, URL-path, and new query string in the RewriteRule substitution field.
  • Use [R=301,L] flags on the rule to invoke an external redirect and end mod_rewrite processing.

    See the resources cited in our Forum Charter, the example threads and tutorials in our Forum Library, and previous threads on this subject available through our site search facility, then post you best-effort code as a basis for discussion.

    Thanks,
    Jim
  • jmino14

    4:26 pm on Apr 19, 2010 (gmt 0)

    10+ Year Member



    Thanks Jim,

    I have searched everywhere and have not been able to find any documentation for this. Here's the code I have in the .htaccess file:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} ^id=80564(&|$)
    RewriteRule ^product\.jhtm$ [number1direct.com...] [R=301,L]

    It's not working as is.

    jdMorgan

    7:49 pm on Apr 19, 2010 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Please re-read the answer previously posted. It was written in detail and should be read in detail. The answers to both your coding error and your quest for documentation are both there.

    Jim

    jdMorgan

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

    WebmasterWorld Senior Member 10+ Year Member



    See almost-identical thread: [webmasterworld.com...]

    Jim