SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member globalnerds's Avatar
    Join Date
    Jul 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess rewrite causing infinite loop

    I am trying to do the following redirection on my site:

    Code:
    www.allinforwishes.com/pictures
    to go to www.allinforwishes.com/pictures/2010-event-winners
    I have tried the following in my .htaccess file:
    Code:
    redirect 301 /pictures/         /pictures/2010-event-pictures
    This caused an infinite loop. I then tried the following:

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^allinforwishes.org/pictures/
    RewriteRule (.*) http://www.allinforwishes.org/pictures/2010-event-pictures$1 [R=301,L]

    This did nothing.

    Any ideas???

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

    Is 2010-event-winners a file or a subdirectory of pictures? If it's a subdirectory, WHY does it not have a trailing /?

    Because of my penchant on falling back on mod_rewrite, I would use

    Code:
    RewriteEngine On
    # OF COURSE IT DID NOTHING!
    RewriteCond %{HTTP_HOST} ^allinforwishes.org/pictures/
    # The directory will NEVER be in cluded in the {HTTP_HOST}
    # AND that's irrelevant to the redirection
    
    # This is just plain loopy - good thing it can never be used in a redirection
    RewriteRule (.*) http://www.allinforwishes.org/pictures/2010-event-pictures$1 [R=301,L]
    # That merely sends EVERYTHING (including pictures/2010-event-pictures to itself
    # What you want is to redirect pictures/ (or pictures/index.php
    # - if that's the DirectoryIndex) to pictures/2010-event-pictures
    # (whether it's a file or a directory).
    RewriteRule ^pictures/(index\.php)?$ pictures/2010-event-pictures [R=301,L]
    # OR
    RewriteCond %{REQUEST_URI} !pictures/2010-event-pictures
    RewriteRule ^pictures(.*)$ pictures/2010-event-pictures$1 [R=301,L]
    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.

    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
  •