Need help with regular expression

Discussion in 'Programming' started by johncarrera, Feb 8, 2012.

  1. #1
    Hello,

    I am creating a rewriterule for htaccess to make clean urls.

    What I need:

    http://url.com/variable/ -> index.php?p=variable

    That is not a problem. I can do that with this rule:
    RewriteRule ^((\w+)?+)/$ index.php?p=$1
    Code (markup):
    But I need also this kind of urls to work:

    http://url.com/variab.le/

    So there is a dot inside variable. I have tried this kind of code but without success:
    RewriteRule ^((\w+)?(\.)?(\w+)?+)/$ index.php?p=$1
    Code (markup):
    Could somebody please help me out of this problem. :)
     
    johncarrera, Feb 8, 2012 IP
  2. Ultrabooked

    Ultrabooked Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why don't you try this example, it's far more clear and you can edit it yourself due to your needs.

    url.com/variable/ -> index.php?p=variable
    RewriteRule ^([a-zA-Z0-9.]+)/$ /index.php?p=$1 [L]
    Code (markup):
    Here the ([a-zA-Z0-9-]+) means that in the variable $1 there is one or more of the following: either a small letter, a capital letter, a number or ".". Hope that this will help you.
     
    Ultrabooked, Feb 13, 2012 IP