Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member amessinger's Avatar
    Join Date
    Apr 2005
    Location
    Kansas, USA
    Posts
    46
    Member #
    9682
    I just finished writing a bunch of rewrite rules for a client's site, so that links to the old version of the site don't 404 when the redesigned version goes live. Only one rule is giving me trouble, and it may have something to do with serving the test version of the site from a subdirectory of my domain.

    What I'm trying to do is re-direct any traffic from the old site's duplicate home page to the home page of the new site. I'm pretty sure this would work, if it weren't for the subdirectory:

    Code:
    <IfModule mod_rewrite.c>
    
      RewriteEngine On
    
      # LOCALHOST & TEST SITE ONLY. COMMENT OUT NEXT LINE FOR LIVE SITE!
      RewriteBase /testdir/
    
      # LIVE SITE ONLY. COMMENT OUT NEXT LINE FOR TEST/LOCAL SITE!
      # RewriteBase /
    
      # in the real code, a bunch of other rules precede this one
      RewriteRule ^welcome.html{0,1} / [L,R=301]
    
    </IfModule>
    Instead of taking me to the test site's home page, this takes me to my site's home page. Any ideas? Thanks in advance.
    Zenscope Studio
    Quality Website Development and Graphic Design
    Specializing in Independently-Owned Businesses and Non-Profits
    www.zenscope.com

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    I'm... Mildly confused. Can you clarify the structure that you're trying to redirect from/to? Like, some URIs and what they would rewrite to.

  4. #3
    Member amessinger's Avatar
    Join Date
    Apr 2005
    Location
    Kansas, USA
    Posts
    46
    Member #
    9682
    On the test site, the redirection would be from mydomain.com/testdir/welcome.html to mydomain.com/testdir/.

    On the live site, the redirection would be from example.com/welcome.html to example.com/.

    Does that clarify things?

    If it helps, here's an example of a rewrite rule that actually works:

    Code:
    RewriteRule ^faqs.html{0,1} faq/ [L,R=301]
    Zenscope Studio
    Quality Website Development and Graphic Design
    Specializing in Independently-Owned Businesses and Non-Profits
    www.zenscope.com

  5. #4
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    No, no no!!!

    This isn't what mod_rewrite is for...

    You just do the following in the .htaccess file...

    Code:
    Redirect /welcome.html http://mydomain.com
    or

    Code:
    Redirect /testdir/welcome.html http://mydomain.com/testdir
    Couldn't be simpler...

    Sean

  6. #5
    Member amessinger's Avatar
    Join Date
    Apr 2005
    Location
    Kansas, USA
    Posts
    46
    Member #
    9682
    Quote Originally Posted by seanmiller
    No, no no!!!

    This isn't what mod_rewrite is for...
    Why not? The approach I'm taking is functionally equivalent, and has the benefit of being domain independent. The mod_rewrite module is for rewriting URLs; that's what I'm doing.

    Tangential Tip: For permanent address changes like the ones I'm talking about, it would be better to use "Redirect permanent" instead of just "Redirect". This ensures that HTTP status code 301 (moved permanently) is sent to any user agent requesting the moved files. That doesn't matter much for browsers, but it matters a lot for search engine spiders. Google officially recommends 301 redirects as the surest way to get your old URLs replaced with the new ones in their index.

    In the code sample from my first message, responding with the proper HTTP status code is done with "R=301".
    Zenscope Studio
    Quality Website Development and Graphic Design
    Specializing in Independently-Owned Businesses and Non-Profits
    www.zenscope.com

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Simply going by a diff of the rewrite rule that works vs the one that doesn't, the leading / might be making an absolute path out of something you're expecting will be a relative path. I can't recall how leading /s play with the RewriteBase, but it might be worth trying to make the rule redirect to the actual file (index.html instead of /, for example).


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:19 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com