mod_rewrite : allow spaces

Discussion in 'Apache' started by swissmiss, Mar 17, 2007.

  1. #1
    Hello. :)

    RewriteRule ^users/([A-Za-z0-9-]+)+$ /file.php?uname=$1
    Code (markup):
    how can i modify that to allow a space?

    I've tried the following (added space) but I get a "Internal Server Error" :

    RewriteRule ^users/([A-Za-z0-9- ]+)+$ /file.php?uname=$1
    Code (markup):

    Should be fairly simple answer. Thank you for your time.

    :)
     
    swissmiss, Mar 17, 2007 IP
  2. JoshuaGross

    JoshuaGross Peon

    Messages:
    411
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use \s instead of a space.
     
    JoshuaGross, Mar 17, 2007 IP
  3. swissmiss

    swissmiss Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi, thanks for the reply!
    
    RewriteRule ^users/([A-Za-z0-9-\s]+)+$ /file.php?uname=$1
    Code (markup):
    Like that? Internal server error again..
     
    swissmiss, Mar 17, 2007 IP
  4. JoshuaGross

    JoshuaGross Peon

    Messages:
    411
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Remove the last + sign.... whether or not it's causing the error, it's useless.

    + means "one or more", but the only thing being repeated is the [A-Z...] which already has a + after it.

    Let me know if that solves anything.
     
    JoshuaGross, Mar 17, 2007 IP
  5. swissmiss

    swissmiss Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    RewriteRule ^users/([A-Za-z0-9-\s]+)$ /file.php?uname=$1
    Code (markup):
    Thanks, removed that. :) Still same error though.
     
    swissmiss, Mar 17, 2007 IP
  6. JoshuaGross

    JoshuaGross Peon

    Messages:
    411
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try escaping the dash.

    RewriteRule ^users/([A-Za-z0-9\-\s]+)$ /file.php?uname=$1
    Code (markup):
     
    JoshuaGross, Mar 17, 2007 IP
  7. swissmiss

    swissmiss Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    getting closer :D Now I get a "Not Found 404"... The browser replaces the space with a %20 if that makes a difference.

    Thanks for you help!!
     
    swissmiss, Mar 17, 2007 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #8
    RewriteRule ^users/(.*)$ /file.php?uname=$1
     
    Nintendo, Mar 17, 2007 IP
  9. swissmiss

    swissmiss Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    ahh that works. :) Thanks. Although, I would like to limit the input. I guess until i find a solution for the other way I'll just do a little PHP validation.
     
    swissmiss, Mar 20, 2007 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #10
    RewriteRule ^users/([^.]+)$ /file.php?uname=$1 [L]

    (.*) is anything. ([^.]+) is more limited, but I'm not sure if it would work with a space.
     
    Nintendo, Mar 20, 2007 IP
  11. vasim.padhiyar

    vasim.padhiyar Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #11
    I am trying to change redirect url1 to url2

    url1 = http://localhost/ad/profile/2/Vasim Padhiyar/

    url2 = http://localhost/ad/public_profile.php?id=2&name=Vasim Padhiyar

    i am using following code

    RewriteRule ^profile/(.*)/(.*)/$ public_profile.php?id=$1&name=$2 [L]
    Code (markup):
    The code only works if i type following url

    url1 = http://localhost/ad/profile/2/Vasim/

    Any idea ?

    Thanks in advance.
     
    vasim.padhiyar, Dec 14, 2011 IP
  12. muthukumar664

    muthukumar664 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Hi,

    Kindly remove the space in between the file name to resolve the issue.
     
    muthukumar664, Dec 15, 2011 IP