SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: 301 Redirect

  1. #1
    SitePoint Enthusiast MSWD's Avatar
    Join Date
    Nov 2007
    Location
    Texas
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 Redirect

    Can anyone help me? We have moved from beaconelectricalservice.com to prolectricllc.com. I want to write a 301 redirect in my htaccess file that will get everything to redirect.

    right now I have:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://www.prolectricllc.com/$1 [R=301,L]

    And it redirects the main url. BUT how do you get the individual links to redirect to the new pages. The new pages are not named the same;

    Example:
    Original : http://www.beaconelectricalservice.c...iendswood.html
    New: http://www.prolectricllc.com/electri...iendswood.html

    I have the individual pages indexed by google so in the SERP's they click the electricianfriendswood.html link and they get a 404

    How can I get all pages to redirect?

    Please offer specific instructions as I don't have much experiences with htaccess

    Thanks for your help in advance!

  2. #2
    SitePoint Enthusiast MSWD's Avatar
    Join Date
    Nov 2007
    Location
    Texas
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ended up redirecting each page individually to the new page.

    It's working now, but was there an easier way to accomplish this?

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Kathy,
    Quote Originally Posted by MSWD View Post
    Can anyone help me? We have moved from beaconelectricalservice.com to prolectricllc.com. I want to write a 301 redirect in my htaccess file that will get everything to redirect.
    Did you try
    Code:
    Redirect 301 / http://www.proectricllc.com/
    That should do the trick for you!

    UNLESS both domains are colocated in which case, use mod_rewrite:
    Code:
    RewriteCond %{HTTP_HOST} beaconelectricalservice\.com [NC]
    RewriteRule .? http://www.prolectricllc.com%{REQUEST_URI} [R=301,L]
    # note, %{REQUEST_URI} is already available - no need to fetch it again with (.*)
    right now I have:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://www.prolectricllc.com/$1 [R=301,L]

    And it redirects the main url. BUT how do you get the individual links to redirect to the new pages. The new pages are not named the same;

    Example:
    Original : http://www.beaconelectricalservice.c...iendswood.html
    New: http://www.prolectricllc.com/electri...iendswood.html

    I have the individual pages indexed by google so in the SERP's they click the electricianfriendswood.html link and they get a 404

    How can I get all pages to redirect?

    Please offer specific instructions as I don't have much experiences with htaccess

    Thanks for your help in advance!
    Either of the above code samples will do just that for you.

    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

  4. #4
    Non-Member
    Join Date
    Apr 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it doesnt work in my end.

  5. #5
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    I ended up redirecting each page individually to the new page.

    It's working now, but was there an easier way to accomplish this?
    Since one old page goes to some otherly-named new page, would a rewrite map be of use here?

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    cal,
    Quote Originally Posted by caldream View Post
    it doesnt work in my end.
    First, welcome to SitePoint's Apache forum.

    Second, was that a question?

    S-p,
    Quote Originally Posted by Stomme poes View Post
    Since one old page goes to some otherly-named new page, would a rewrite map be of use here?
    I believe the page names remained the same, just the domain changed. With no response back from the OP, I'm guessing that the problem is solved.

    BTW, use of a RewriteMap requires access to the httpd.conf so this is not available to most people (certainly not to those who don't know to ask about it). That's for good reason: You can take down the entire server if the script is not properly written!

    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

  7. #7
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Ah. I asked because link1 in the OP is
    electricianfriendswood.html
    and the second was
    electrician_friendswood.html
    as well as new domain name.

    Besides rewrite map, and besides manually redirecting each file that got a new name, is there... some other way?

    I dunno if this would work, but on Unix you can take a file and make it a link to another file. Could something like that be done?

    Code:
    ln electricianfriendswood.html electrician_friendswood.html
    ?

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

    Good catch! I didn't see that (either)! No, when someone does NOT plan changes like that, it can (and generally does) end up in a disaster).

    Yes, I suppose that symbolic links would work but they are a lot of work in themselves, aren't they? IMHO, do the same work as for a RewriteMap and put it in a PHP script which can read the "map" in a database and perform a header('location:') redirection - but ONLY if you fail to maintain the same filenames!

    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
  •