SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast Brocberry's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 a whole site but also redirect specific pages

    The site is an Opencart shopping cart of perhaps 100 pages; 4 of them valuable. I would like to 301 those four pages to particular page on a new site, and also 301 the whole site/all the other pages to the new site. Does it make sense to do this and if so how?

    Many thanks.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    BB,

    Yes, read the tutorial linked in my signature. Then, if, after reading the coding examples, you're still having problems, provide your sample code, your test URIs and their results and I'll get you through this.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Enthusiast Brocberry's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi DK

    I haven't written it yet as I don't know who to do the the pages don't require individual redirects. This is what I have planned so far:


    RewriteEngine on

    Redirect 301 /index.php?route=product/product&product_id=1 http://www.new.com/new1
    Redirect 301 /index.php?route=product/product&product_id=2 http://www.new.com/new2
    Redirect 301 /index.php?route=product/product&product_id=3 http://www.new.com/new3
    Redirect 301 /index.php?route=product/product&product_id=4 http://www.new.com/new4

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Bb,

    From others' questions, Redirect does not examine the query string therefore your code, while a good attempt, won't work.

    The alternative is to use mod_rewrite which CAN examine the query string and use the value of a key in the redirection. An example, using YOUR coding above, would be:
    Code:
    RewriteEngine on
    RewriteCond %{QUERY_STRING} product_id=(/d+)
    RewriteRule ^index\.php$ http://www.new.com/new%1
    Of course, if the values of product_id are not digits or cannot be appended to new on the new server, my example code must change.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Enthusiast Brocberry's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks very much, dklynn. The URIs I gave aren't far off the actual, but I didn't realise it would be so complicated, so I ought to give you something more precise, thanks for bearing with me here.


    http://www.old.com/index.php?route=product/product&product_id=49 >> http://www.new.com/item-aaa
    http://www.old.com/index.php?route=product/product&product_id=50 >> http://www.new.com/item-bbb
    http://www.old.com/index.php?route=product/product&product_id=51 >> http://www.new.com/item-ccc
    http://www.old.com/index.php?route=product/product&product_id=52 >> http://www.new.com/item-ccc


    Everything blue is the literal copy & paste from the old domain with only the domain name changed to old.com. The red in the new domain isn't the actual copy and paste but it is the correct format in the sense that it is a hyphenated name with no numbers and no .html or .php at the end, as the Drupal cms has created an alias.

    I would like to redirect is the home page

    http://www.old.com >> http://www.new.com


    In fact, I would also like to pass the whole site to the new one... there are dozens of other miscellaneous pages that can all point to the new site's home page.

    Thanks for any help.

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Bb,

    I can see why you wouldn't have shown the real redirections ...

    ... because there is no way for mod_rewrite to map using your query string (route=product/product&product_id=49) to item-aaa. Like I tell people, I may be psycho but I'm not psychic! Same for Apache's mod_rewrite.

    Now that you've been "properly chastised," you can make these redirections (hard-coded) so I'll hope you don't really have dozens. If you do have that many (AND access to the httpd.conf), you can use a RewriteMap. Yeah, I didn't think the server belonged to you (because you're moving) so there is a "poor man's RewriteMap" which you can use: If you see your query string, redirect to a "handler file" which can read {THE_REQUEST} and have it lookup the redirection then use PHP to redirect to the new URL. Oh, yes, all this is in my signature's tutorial.

    As for your redirection from old.com to new.com, that's a piece of cake (but I'll refer you to the example section of the tutorial).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •