Results 1 to 3 of 3
  1. #1
    Hot doggy hellhound's Avatar
    Join Date
    May 2006
    Location
    Cheshire, England
    Posts
    28

    mod_rewrite: replace 1 or more instances of a character?

    Basically what I need to do is this...

    1. Replace every space in the URL with an underscore, preferably without redirecting yet
    2. Continue to process next .htaccess commands (.......rest of .htaccess file goes here)

    First of all I don't know whether to check for a space or a %20...

    I just can't puzzle this one out and there don't seem to be any relevant examples out there. Can anyone help? Thanks in advance.

  2. #2
    Senior Member
    Join Date
    Aug 2003
    Location
    Westgate-on-Sea, Kent, ENGLAND
    Posts
    2,228
    This one had me stumped too as it's far from straightforward! I did some googling and came up with a solution which almost worked...so i finished it off and fixed a bug in it.

    Try this:

    Code:
    Options +SymlinksIfOwnerMatch
    
    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} ^(.*)\ (.*)$
    RewriteRule ^.*$ %1_%2 [E=space_replacer:%1_%2]
    RewriteCond %{ENV:space_replacer} !^$
    RewriteCond %{ENV:space_replacer} !^.*\ .*$
    RewriteRule ^.*$ %{ENV:space_replacer} [R=301,L]
    
    ....rest of rules here...
    (careful with the spaces - if you copy and paste from above it should work though)

    Andy

  3. #3
    Hot doggy hellhound's Avatar
    Join Date
    May 2006
    Location
    Cheshire, England
    Posts
    28
    Quote Originally Posted by Andy
    Try this: [...]
    Thanks for your reply, Andy. Unfortunately I couldn't figure out quite what your solution was doing, but it wasn't replacing when there were two or more spaces.

    I think it may be impossible! Oh well, just means I'll have to keep using a slightly less spiffy workaround.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •