SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to use .httaccess to eliminate redundant domains indexed in Google.

    Every page of my website mysite2.com is indexed in Google twice.
    The redundant entries are URLs that use my old domain name mysite1.com.
    I am trying to use wildcard redirects in my .httaccess file to have any
    URL with the old domain name redirect to the new domain.
    I tried the following:
    Redirect 301 / http://www.mysite2.com/
    but this caused a server error.
    I suspect the error was caused because I have a few redirect statements
    that redirect a few special pages to a 3rd-party website because those special
    pages really have moved somewhere else.
    Also, there are already several hundred redirects in my .httaccess file because
    I recently migrated my .HTML pages to .PHP pages with more SEO-friendly hyphenated
    names.
    I need a wildcard solution to make sure that any URL that uses the old domain name
    gets redirected to the new domain name.
    I also need to know if I need to use rewrite statements in conjunction with redirects.
    Please help.

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

    Welcome to SitePoint!

    The response to your question (assuming co-located files) is simply to test for the new domain and, if not being used, redirect:

    Code:
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} !^newdomain\.com$ [NC]
    RewriteRule .? http://newdomain.com%{REQUEST_URI}
    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    One of the first things to learn about using .htaccess is DON'T! If you have hundreds of lines, you're abusing your server and should be banned from shared servers (and VPS's). If you seriously need those lines of code, have your host add them to your httpd-vhosts.conf file or into the httpd.conf while specifying your account.

    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 Member
    Join Date
    Feb 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    David,
    Thanks for your excellent help and the link to the tutorial! Also thanks for the advice about having too many statements in my .httaccess file. I am pursuing that issue with my host.
    Thanks,
    Joe

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



    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
  •