Rewriting URLs with spaces

Discussion in 'Apache' started by ChocolateLover, Apr 2, 2009.

  1. #1
    I am working on a website that has URLs that have been indexed by search engines etc. Many of these URLs have spaces.

    In the first instance I want to redirect the URLs that no longer exist.
    Example pics/Red car.php to go to pics/solar-racer.php

    This is my rule
    RewriteRule ^pics/Red car.php pics/solar-racer.php [L]
    Code (markup):
    Leaving a space between Red and car gives me:
    The server encountered an internal error or misconfiguration and was unable to complete your request.

    I've read:
    "\ " is a way of expressing spaces in mod rewrite
    and
    "\s" is a way of matching spaces

    I've tried
    RewriteRule ^pics/Red\scar.php pics/solar-racer.php [L]
    Code (markup):
    but this rule doesn't seem to pick up the pics/Red car.php URL at all.

    I will look at replacing all spaces with hyphens but need to sort this problem first.
    Any help would be appreciated.
     
    ChocolateLover, Apr 2, 2009 IP
  2. norbert

    norbert Guest

    Messages:
    61
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    (not tested)
    
    RewriteRule ^pics/Red( )car.php$ pics/solar-racer.php [L]
    
    Code (markup):
     
    norbert, Apr 4, 2009 IP