([a-zA-Z0-9_-]+) how to allow "."-VBForums
Results 1 to 13 of 13

Thread: ([a-zA-Z0-9_-]+) how to allow "."

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    874

    ([a-zA-Z0-9_-]+) how to allow "."

    Hi there, does anyone know the correct way of changing this

    Code:
    ([a-zA-Z0-9_-]+)
    to allow full stops ?? ex : "."

    Thanks Jamie

  2. #2
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    use \.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    874

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    Hi, Is this right? as it now just takes me to a error 404 page,
    Code:
    RewriteRule ^(\.[a-zA-Z0-9_-]+)$ profile.php?id=$1
    RewriteRule ^(\.[a-zA-Z0-9_-]+)/$ profile.php?id=$1
    thanks

  4. #4
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    No, like this:
    ^([a-zA-Z0-9_-\.]+)$

    The brackets create a character class. For example, [a] matches one 'a'; [a-z] matches any character between 'a' and 'z'. The + symbol means match at least once: [a-z]+ means one or more characters between 'a' and 'z'.

    The full stop . symbol matches any character. In order to match that particular symbol, you need to escape it with the backslash. The backslash causes the following character to be interpreted literally, ignoring any special meaning.

    When you added it outside the character class, you created an expression which matches a full stop followed by one or more characters within those ranges. Moving the full stop inside the character class will give you the effect you want.
    Last edited by penagate; Feb 13th, 2012 at 07:22 PM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    874

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    Hi thanks for the reply. but thats now giving me a 500 internal server error, any ideas on how i can fix that? thanks

  6. #6
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,504

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    Did you enable RewriteEngine ("RewriteEngine on") prior to your RewriteRules? You could post the full contents of your htaccess file (assuming that's where you're working) for better help - anything that's messed up in there could cause the problem.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    874

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    Hi this is my htacess file

    Options -Indexes
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^([^/]+)/$ $1.php

    # Forces a trailing slash to be added
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]
    RewriteRule ^([a-zA-Z0-9_-\.]+)$ profile.php?id=$1
    RewriteRule ^([a-zA-Z0-9_-\.]+)/$ profile.php?id=$1

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    874

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    p.s, the part in red is causing the internal error,

    Thanks

  9. #9
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,504

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    It seems like it's trying to interpret "_-\" as a character set, like "A-Z," except "_-\" makes no sense and is resulting in an error. Try moving the \. to a position where this sequence won't occur:
    Code:
    RewriteRule ^([a-zA-Z0-9\._-]+)$ profile.php?id=$1
    RewriteRule ^([a-zA-Z0-9\._-]+)/$ profile.php?id=$1

  10. #10
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    Good spotting — the hyphen-minus should be escaped as well:

    ^([a-zA-Z0-9_\-\.]+)$

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    874

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    Hi for some reason, when i do either of the above it seems to ignore the following from my htaccess

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^([^/]+)/$ $1.php

    # Forces a trailing slash to be added
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]

    it automatically thinks any thing i goto on my site is a profile.php

    any ideas?

    thanks!

  12. #12
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    try adding [L] to the end of the first RewriteRule.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    874

    Re: ([a-zA-Z0-9_-]+) how to allow "."

    Internal server error when i add [L]


    Thanks

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.