mod rewrite infinite loop

Discussion in 'Apache' started by dave487, Dec 7, 2005.

  1. #1
    I have created a rewrite rule which works fine.

    I tried to do a php redirect from the old dynamic page to the new static looking page but this gave an infinite loop.

    How can I get round this?

    the reason I am using php to redirect instead if doing the redirect in mod rewite is the old url's have a + in them which I wan to convert to a - for the new url.

    Many thanks.
     
    dave487, Dec 7, 2005 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Post the .htaccess code.
     
    Nintendo, Dec 7, 2005 IP
  3. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OK my htaccess looks like this:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule repairers/(.*)/(.*)/$ /repairers.php3?$1=$2
    HTML:
    which works fine.

    How do I redirect the old page to the new page?
    I tried to add the following to the top of the page but this obviously gets stuck in a loop. I am sure there is a standard way to do this but don't know it.

    if($name!=""){
    		$repname = str_replace("+", "-", $name); 
    		header("HTTP/1.1 301 Moved Permanently"); 
    		header("Location: http://www.noblemarine.co.uk/repairers/name/$repname/"); 
    		exit();	
    }
    PHP:
     
    dave487, Dec 8, 2005 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    I stink at php. I would just use mod_rewrite to redirect it.

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^repairers.php3?$1=$2$ http://www.domain.com/repairers/(.*)/(.*)/ [R=301,L]

    Is both the old and new URL using the same script, with

    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.noblemarine.co.uk/repairers/name/$repname/");

    in it? If it is, the new URL also generates that, probably causing it to flip out, old URL, no, new URL, no, new URL, no new URL...
     
    Nintendo, Dec 8, 2005 IP
  5. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Problem solved- thanks for the assistance.

    For anybody else doing the same the simplest way to do this was to not try to use the same script to handle both the old url and the new, rewritten url.
     
    dave487, Dec 8, 2005 IP