Some Help Please

Discussion in 'Apache' started by t0mb, May 6, 2008.

  1. #1
    Hi guys,

    I have just switched hosts and my new host does not automatically redirect flat links.

    example - http://www.absale.com/page gives 404 error instead of going to page.html

    I have added this code to the .htaccess

    RewriteRule ^(.+)$ http://www.absale.com/$1.html [R=301,NC]

    Unfortunately that produces an endless string .html.html.html.html

    What have I overlooked?
     
    t0mb, May 6, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    (.+) will capture any character, once or more times. It will therefore, create an infinite loop as you've suggested.

    You should use a different rule, i.e. to only capture URL's that don't contain a full stop.

    Jay
     
    jayshah, May 7, 2008 IP
  3. t0mb

    t0mb Active Member

    Messages:
    1,116
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #3
    t0mb, May 7, 2008 IP
  4. apachehtaccess

    apachehtaccess Guest

    Messages:
    82
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    From the advanced .htaccess tutorial.

    This code will only perform the redirect if the request is not a directory, and if the request.html exists. Much better/safer.

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^([^\.]+)$ http://www.absale.com/$1.html [R=301,NC]
    Code (markup):
     
    apachehtaccess, May 9, 2008 IP