PLEASE assist with 301 redirect in .htaccess?

Discussion in 'Apache' started by GadgetMadness.com, Sep 11, 2007.

  1. #1
    Hi, I recently changed the URL structure on our site and could really use some help getting a 301 redirect to direct users to the new structure:

    Old site URL: http://www.domain.com/BabyGadgets-Baby_Gadgets
    New site URL: http://[COLOR="Red"]shop[/COLOR].domain.com/BabyGadgets-Baby_Gadgets
    Code (markup):
    There are several instances like this (Music-Music_CD, Books-Geek_Books) however if someone could please show me the basic redirect I can replicate it for the other ones. Thanks so much for your help, it's greatly needed and appreciated!

    UPDATE:

    To be more specific, what I have listed above is the general URL structure to be redirected. However the URL's look more like this:

    http://shop.domain.com/BabyGadgets-165797011-B000FHD0NC-Pampers_Cruisers_Size_4_Economy_Plus_Pack_140_Cruisers
    http://shop.domain.com/BabyGadgets-165797011-B000FH1DRC-Pampers_Swaddlers_Size_2_Economy_Plus_Pack_184_Swaddlers
    Code (markup):
    Redirecting just the basic URL structure I originally listed would be pretty simple. Writing the .htaccess to 301 redirect each and every URL is what I am stuck on.
     
    GadgetMadness.com, Sep 11, 2007 IP
  2. petyard

    petyard Well-Known Member

    Messages:
    2,025
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    185
    #2
    petyard, Sep 11, 2007 IP
  3. GadgetMadness.com

    GadgetMadness.com Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Why yes I did actually. As I am not a programmer I opened a thread requesting assistance in the Apache forum where other users have also posted similar threads requesting assistance. If I knew how to do this or could figure it out I would have done so already, trust me.

     
    GadgetMadness.com, Sep 11, 2007 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    Ignore that n00bie who doesn't know forums are for asking questions!!

    domain.com/.htaccess

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)$ http://shop.domain.com/$1 [R=301,L]
     
    Nintendo, Sep 11, 2007 IP
  5. GadgetMadness.com

    GadgetMadness.com Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the reply! I think I failed to describe the situation properly, I apologize. I'll just post the direct URL's so you can see what I mean.

    I'm not actually redirecting all url's to the new subdomain, just URL's that meet specific criteria. For example below is a valid URL on the domain that should not be redirected:

    http://www.gadgetmadness.com/archives/20070909-review_squawkers_mccaw_robot_parrot.php
    Code (markup):
    Here is an example of a URL that is currently resulting in a 404 that should be redirected to the subdomain:

    http://www.gadgetmadness.com/Software-13286361-Jai_Alai
    Code (markup):
    So the redirected 301 would then be:

    http://shop.gadgetmadness.com/Software-13286361-Jai_Alai
    Code (markup):
    The .htaccess rule I am asking for help with would use the shop category name as the criteria for redirection, some examples would be:

    .com/Electronics-High_Tech_Gadgets
    .com/Wireless-Cell_Phones

    Here's an example of what's happening. If you copy and paste the link below into your browser:

    http://tinyurl.com/2bnzfp
    Code (markup):
    That Ask.com search result is pointing to the old URL, which when clicked results in a 404.

    All of these pages existed on the primary domain previously, I recently moved the shop to its own subdomain. I hope this explains it better, and thanks so much for the help!
     
    GadgetMadness.com, Sep 11, 2007 IP
  6. petyard

    petyard Well-Known Member

    Messages:
    2,025
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    185
    #6
    ...:rolleyes:
    forums are for asking questions...but nothing is easy..you need to try and try more before asking for help
    dont you agree?
    :rolleyes:
     
    petyard, Sep 11, 2007 IP
  7. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #7
    Only way would be if there is something unique in the shop URLs not on the rest of the site. Like

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)\-(.*)$ http://shop.domain.com/$1-$2 [R=301,L]

    if nothing else on the site is like domain.com/anything-else

    And if directories get redirected, ([^.]+) might fix it.
     
    Nintendo, Sep 11, 2007 IP
  8. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #8
    Are the archived/other pages static? If not, then can you post your existing mod_rewrite rules. Otherwise, this should work, as it only rewrites the requests if they are not pointing to files that don't already exist (such as your archive pages, and also images, CSS etc.)

    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ http://shop.domain.com/$1 [R=301,L]
     
    krt, Sep 11, 2007 IP
  9. GadgetMadness.com

    GadgetMadness.com Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yes, the other pages are static. I'll give both of these suggestions a shot and let you know how it works!

     
    GadgetMadness.com, Sep 12, 2007 IP