SitePoint Sponsor

User Tag List

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

    Should this 301 be working? Is this a code error or 1and1 error?

    Code:
    AddType x-mapp-php5 .php #Required for 1and1 server which is php4  by default
    
    Options +FollowSymlinks
    RewriteEngine On
    
    Redirect 301 /index.php?route=product/product&product_id=51 http://www.newdomain.com/new-page

    For posting here, I have changed the new domain name, but the rest of it is the code copied from the htaccess I wrote.

    If I code it domain-to-domain, like this:

    Code:
    RewriteRule (.*) http://www.new.com/$1 [R=301,L]
    the 301 works, but the page-to-page 301 is not working.

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

    First, 1&1 is known to be a horrible host.

    Second, I don't believe Redirect can access the query string as your Redirect statement is attempting - you need mod_rewrite for that.

    Third, (.*) will match EVERYTHING and redirect to new.com. It retains the {REQUEST_URI} variable as well as the {QUERY_STRING} so, if the scripts (including database and CMS configuration) are identical, it should work exactly the same at new.com.

    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)
    Thanks DK

    I have found a solution to the query string problem but I'm still struggling with an instruction to redirect the remaining pages to the a single page.

    For the query string problem

    Code:
    RewriteCond %{QUERY_STRING} ^string-after-the-question-mark-of-old-url$
    RewriteRule ^index.php$ http://www.new.com/new? [L,R=301]

    I will write a variation of that for several different pages. But I also need to redirect the rest of the site to the index page of the new site.

    If I try the following:

    Code:
    Redirect 301 / http://www.new.com/
    it keeps everything after the forward slash in the redirect, so

    old.com/this becomes new.com/this

    Perhaps this is because of the query string problem, I don't know. All the pages have the question mark. If so perhaps I need code that would fulfil this pseudo code:

    Code:
    RewriteCond %{QUERY_STRING} ^(Wild card)$
    RewriteRule ^index.php$ http://www.new.com? [L,R=301]

  4. #4
    SitePoint Enthusiast Brocberry's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (.*) used as wild card works

    Done.

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



    QSA flag is what you need - it retains any query string when you're creating a new query string, otherwise, it'll be sent along anyway. In short, ARGH! You don't want/need (.*)!

    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

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

    The new site has clean URLs. The question mark at the end of the destination URL is possibly just wrong and misleading but the code above is sending any URL with a query sting to the home page of the new destination site.

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

    Okay, I must have misread what you were trying to do:

    1. To retain a query string, do nothing.

    2. To retain a query string and add another term, add the term and use the [QSA] flag.

    3. To replace a query string, simply add the replacement query string.

    4. To KILL a query string, add the ? to the redirection (it will NOT be displayed, it will merely tell Apache to ignore the existing query string).

    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


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
  •