SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess redirect not working

    I have added redirects to my .htaccess file.
    Code:
    Redirect 301 /portfolio_projlist.html http://www.jayrhindbuilders.com/selected-project-list/
    Redirect 301 /portfolio_5res7.html http://www.jayrhindbuilders.com/portfolio/
    #Redirect 301 /index.html http://www.jayrhindbuilders.com/
    Redirect 301 /a http://www.jayrhindbuilders.com/
    Redirect 301 /portfolio.html http://www.jayrhindbuilders.com/portfolio/
    Redirect 301 /contact.html http://www.jayrhindbuilders.com/contact/
    All of them are working except the one commented out, which brings up the error message:
    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
    What am I missing?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,899
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    Is there another setting somewhere that automatically adds the /index.html to the URL when you request / ?
    In that case it would constantly redirect from / to /index.html to / to /index.html to / etc etc ...

    That's the only thing I can think of now; when I try your code on my host it works fine, redirects /index.html to / and then stops
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    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)
    Rémon,

    Quite correct: DirectoryIndex is likely to be index.html ON THE SAME SERVER, i.e., LOOPY!

    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
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked http://www.jayrhindbuilders.com/index.html with the redirect commented out in the .htaccess file. I come up with a 404 page not found error.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  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)
    Paul,

    I clicked the link with index.html and it did give a 404. I then altered the index.html (with 404 contents, i.e., your 404 redirection was both not using ErrorDocument and not 301'd) to index.php and got the blank URI (redirection) with the home page.

    Since there is no reason for anyone to link to index.html if it's not there, (1) use DirectoryIndex index.php and (2) use ErrorDocument 404 / or add an R=301 flag to your redirection for 404's (better yet, do both!).

    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
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason I need the redirect for .html is that Google still shows links to that URL after relaunching the site about a year ago. DK, I do not fully understand your suggestion. Can you show me code?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  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)
    Paul,

    I'm not sure what you're using to remove index.php (Berkshire home builders | Jay Rhind Builders | Stockbridge MA resolved to Berkshire home builders | Jay Rhind Builders | Stockbridge MA hiding the default script) from the URI so there are other things going on which you've not shown.

    As for your code, I'm not sure what mod_alias's handling of internal absolute links does, however, had I written your Redirects, I would have known that they were in the .htaccess of the DocumentRoot and eliminated the leading /'s you'd used (the /a may be problematic, too!).

    As for index.html being served a 404 script is another oddity which is not displayed with your first post. The ErrorDocument statement's syntax is

    ErrorDocument {status is optional} {file/directory to redirect} {ABSOLUTE redirection}

    where, for the 404 case I'd encountered, {status is optional} = 404, {file} was index.html (not /index.html) and the {ABSOLUTE redirection} could be either internal (/index.php or just plain / to let DirectoryIndex look for the default scripts in order) or the full URL which you've used.

    Since your question was "What am I missing?", I believe that, lacking other details, it would be that you do not need (and, apparently, Apache doesn't like) leading /'s in the file/directory part of the statement.

    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

  8. #8
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Re
    lacking other details, it would be that you do not need (and, apparently, Apache doesn't like) leading /'s in the file/directory part of the statement.
    I tried removing the leading / from
    Code:
    Redirect 301 /index.html http://www.jayrhindbuilders.com/
    and still get the same 404 error message.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  9. #9
    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)
    Paul,

    What about
    Code:
    Redirect 301 index.html /index.php
    OR
    Code:
    DirectoryIndex index.php
    
    Redirect 301 index.html http://www.jayrhindbuilders.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

  10. #10
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    None of these worked.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  11. #11
    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)
    Paul,

    Bummer! Since there is no reason for it not to work (with what you've shown above), either show your entire .htaccess OR use mod_rewrite for that one:
    Code:
    # after all your Redirect statements AND
    # assuming Apache 2.x
    
    RewriteEngine on
    RewriteRule ^index\.html http://www.jayrhindbuilders.com/ [R=301,L]
    # if Apache 1.x, insert a / between ^ and index
    BECAUSE there is no reason for Redirect not to do this successfully, I'd recommend showing your .htaccess as there is something going on there which is preventing the intended Redirection.

    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

  12. #12
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the complete .htaccess code:
    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    
    #to redirect urls from old to new urls
    Redirect 301 /portfolio_res2.html http://www.jayrhindbuilders.com/portfolio/
    Redirect 301 /portfolio_5res4.html http://www.jayrhindbuilders.com/portfolio/
    Redirect 301 /portfolio_5res1.html http://www.jayrhindbuilders.com/portfolio/
    Redirect 301 /portfolio_5res6.html http://www.jayrhindbuilders.com/portfolio/
    Redirect 301 /portfolio_5res2.html http://www.jayrhindbuilders.com/portfolio/
    Redirect 301 /portfolio_res1.html http://www.jayrhindbuilders.com/portfolio/
    Redirect 301 /portfolio_res6.html http://www.jayrhindbuilders.com/portfolio/
    Redirect 301 /portfolio_projlist.html http://www.jayrhindbuilders.com/selected-project-list/
    Redirect 301 /portfolio_5res7.html http://www.jayrhindbuilders.com/portfolio/
    #Redirect 301 /index.html http://www.jayrhindbuilders.com/
    Redirect 301 /a http://www.jayrhindbuilders.com/
    Redirect 301 /portfolio.html http://www.jayrhindbuilders.com/portfolio/
    Redirect 301 /contact.html http://www.jayrhindbuilders.com/contact/
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  13. #13
    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)
    Paul,

    A couple of comments, if I may, before telling you what's causing your problem:

    1. Using <IfModule> tests on every request is an abuse of the server. If you were on my server, I'd cancel your account. I have a standard rant for that but you've had enough problems that it might be overboard.

    2. RewriteBase is a horrible bit of code designed to UNDO a mod_alias redirection so it should be removed.

    BOTH of those are in the WP-generated code but, take my word for it, they do that for newbies who don't have a clue. You are not in that class so get rid of them.

    The problem is that you've allowed the WP code to redirect to index.php before your redirections. Uh, oh! On second thought, (1) mod_alias is a core module so it takes precedence over mod_rewrite and (2) your other Redirect code is working.

    Other thoughts:

    A. Your server may have Options MultiViews set and that could, as always, cause problems (here, redirecting to the other index.whatever file).

    B. Your WP code is serving to redirect 404s to index.php and provide WP's 404 response (which, if memory serves, is what I received when I tested your link). It's my guess that this is what's happening.

    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

  14. #14
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks DK. So what do you suggest I replace for the WP code?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  15. #15
    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)
    Paul,

    I would:

    1. Move the WP code below the Redirects

    2. Uncomment the index.html Redirect

    3. Add (at the top) DirectoryIndex index.php (which will redirect / to index.php internally).
    Code:
    # My general layout
    # Core directives, i.e., Options, DirectoryIndex, ErrorDocument (WP takes care of this)
    
    # Core redirections (i.e., your Redirect statements)
    
    # mod_rewrite statements
    # WP mod_rewrite should be "corrected" by removal of
    # -  <IfModule> wrapper
    # -  RewriteBase directive
    ... for the reasons in the thread post above.

    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
  •